Skip to content
Merged

Dev #38

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions R/ReadWriter.R
Original file line number Diff line number Diff line change
Expand Up @@ -1157,15 +1157,19 @@ qs.2.table <- function(path, out_file = c("tsv", "csv", "csv2", "excel")[1]) {

# Base name (without extension) shared by all output formats
base_filename <- sub("\\.qs$", "", path)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the directory of absolute input paths

When path is absolute, base_filename remains absolute and is passed as manual_file_name, while manual_directory is left unset. construct.file.path() therefore selects getwd() as the output directory and combines it with the absolute-looking filename, so conversions can target a malformed cwd-prefixed path (and the reported out_path does not match it). Pass dirname(path) as manual_directory and the extensionless basename(path) as manual_file_name for every output branch.

Useful? React with 👍 / 👎.

# Split into directory + extensionless file name so absolute paths in `path`
# are preserved (construct.file.path() would otherwise prepend getwd()).
out_dir <- dirname(base_filename)
out_name <- basename(base_filename)

if (out_file == "tsv") {
ReadWriter::write.simple.tsv(data, manual_file_name = base_filename, separator = "\t")
ReadWriter::write.simple.tsv(data, manual_file_name = out_name, manual_directory = out_dir, separator = "\t")
out_path <- paste0(base_filename, ".tsv")
} else if (out_file == "csv") {
ReadWriter::write.simple.tsv(data, manual_file_name = base_filename, separator = ",")
ReadWriter::write.simple.tsv(data, manual_file_name = out_name, manual_directory = out_dir, separator = ",")
out_path <- paste0(base_filename, ".csv")
} else if (out_file == "csv2") {
ReadWriter::write.simple.tsv(data, manual_file_name = base_filename, separator = ";")
ReadWriter::write.simple.tsv(data, manual_file_name = out_name, manual_directory = out_dir, separator = ";")
out_path <- paste0(base_filename, ".csv")
} else if (out_file == "excel") {
# write.simple.xlsx() expects a list of sheets; wrap a bare table into one.
Expand Down