Repository navigation
Fix read.simple.ssv()/write.simple.xlsx() crashes and rewrite qs.2.table() #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -442,6 +442,7 @@ read.simple.csv.named.vector <- function(file, sep = ";", col_names = FALSE, | |
| #' @param wRownames With row names? Default: TRUE. | ||
| #' @param NaReplace Replace NA values? Default: TRUE. | ||
| #' @param coltypes What type of variables are in columns? Auto-guessing can be very slow. Default: NULL. | ||
| #' @param asTibble Load as tibble or data frame? Default: FALSE (load as data frame). | ||
| #' @examples | ||
| #' \dontrun{ | ||
| #' if (interactive()) { | ||
|
|
@@ -456,14 +457,17 @@ read.simple.csv.named.vector <- function(file, sep = ";", col_names = FALSE, | |
| #' @importFrom gtools na.replace | ||
| read.simple.ssv <- function( | ||
| ..., sep_ = " ", colnames = TRUE, wRownames = TRUE, NaReplace = TRUE, | ||
| coltypes = NULL | ||
| coltypes = NULL, asTibble = FALSE | ||
|
Comment on lines
458
to
+460
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
With the newly exposed Useful? React with 👍 / 👎. |
||
| ) { | ||
| pfn <- Stringendo::kollapse(...) # merge path and filename | ||
| read_in <- suppressWarnings(readr::read_delim(pfn, delim = sep_, col_names = colnames, col_types = coltypes)) | ||
| Stringendo::iprint("New variable dim: ", dim(read_in) - 0:1) | ||
|
|
||
| if (wRownames) read_in <- column.2.row.names(read_in, as_df = !asTibble) | ||
| if (NaReplace) read_in <- as.data.frame(gtools::na.replace(read_in, replace = 0)) | ||
| if (NaReplace) { | ||
| read_in <- gtools::na.replace(read_in, replace = 0) | ||
| if (!asTibble) read_in <- as.data.frame(read_in) | ||
| } | ||
|
|
||
| return(read_in) | ||
| } | ||
|
|
@@ -957,9 +961,10 @@ write.simple.xlsx <- function( | |
|
|
||
| # assign row names if required | ||
| if (isFALSE(has_row_names)) { | ||
| assignRownames <- function(x) column.2.row.names(df, rowname_column = rowname_column, make_names = TRUE) | ||
| assignRownames <- function(x) column.2.row.names(x, rowname_column = rowname_column, make_names = TRUE) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| named_list <- lapply(named_list, assignRownames) | ||
| message("Converting column ", rowname_column, " to row names: ", head(rownames(named_list[[1]]))) | ||
| has_row_names <- TRUE | ||
| } | ||
|
|
||
| FnP <- construct.file.path( | ||
|
|
@@ -1143,34 +1148,24 @@ write.simple.md.table <- function( | |
|
|
||
| qs.2.table <- function(path, out_file = c("tsv", "csv", "csv2", "excel")[1]) { | ||
| # Ensure that the file exists and is a .qs file | ||
| stopifnot(file.exists(path), stringi::stri_detect(str = path, regex = "\\.qs$")) | ||
| stopifnot(file.exists(path), grepl("\\.qs$", path)) | ||
|
|
||
| # Ensure out_file is one of the allowed choices | ||
| out_file <- match.arg(out_file, c("tsv", "csv", "csv2", "excel")) | ||
|
|
||
| # Read in the .qs file | ||
| data <- qs:qread(path) | ||
| data <- qs::qread(path) | ||
|
|
||
| # Determine the output file extension and write the file based on the output format | ||
| path_out <- Stringendo::ppp(base_filename, out_file) | ||
| # Split into directory + base filename (without extension); write.simple.tsv()/ | ||
| # write.simple.xlsx() append the correct extension themselves. | ||
| out_dir <- dirname(path) | ||
| base_filename <- sub("\\.qs$", "", basename(path)) | ||
|
|
||
| if (out_file == "excel") { | ||
| # out_path <- ppp(base_filename, "xlsx") | ||
| Stringendo::ppp(base_filename, out_file) | ||
| ReadWriter::write.simple.xlsx(data, out_path) | ||
| } | ||
|
|
||
| if (out_file == "tsv") { | ||
| ReadWriter::write.simple.tsv(data, path_out, separator = "\t") | ||
| } else if (out_file == "csv") { | ||
| ReadWriter::write.simple.tsv(data, path_out, separator = ",") | ||
| } else if (out_file == "csv2") { | ||
| out_path <- paste0(base_filename, ".csv") | ||
| ReadWriter::write.simple.tsv(data, path_out, separator = ";") | ||
| if (out_file %in% c("tsv", "csv", "csv2")) { | ||
| sep <- switch(out_file, tsv = "\t", csv = ",", csv2 = ";") | ||
| ReadWriter::write.simple.tsv(data, manual_file_name = base_filename, manual_directory = out_dir, separator = sep) | ||
| } else if (out_file == "excel") { | ||
| out_path <- paste0(base_filename, ".xlsx") | ||
| ReadWriter::write.simple.xlsx(data, out_path) | ||
| payload <- if (is.data.frame(data) || is.matrix(data)) list(data) else data | ||
| ReadWriter::write.simple.xlsx(payload, manual_file_name = base_filename, manual_directory = out_dir) | ||
| } | ||
|
|
||
| message("File saved as: ", out_path) | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The committed
man/read.simple.ssv.Rdstill shows the old signature ending atcoltypes = NULLand contains noasTibbleargument entry, so installed help disagrees with the exported function and users cannot discover the new option. Regenerate and commit the Rd output after changing the roxygen block and signature.AGENTS.md reference: AGENTS.md:L21-L24
Useful? React with 👍 / 👎.