Skip to content
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

Feature #375: Allow strings for keepNA argument of writeData(Table)/w… #415

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions R/workbook_write_data.R
Expand Up @@ -130,8 +130,10 @@ Workbook$methods(writeData = function(df, sheet, startRow, startCol, colNames, c




if(keepNA){
if (is.character(keepNA)) {
t[is.na(v)] <- 4L
v[is.na(v)] <- keepNA
} else if (keepNA) {
t[is.na(v)] <- 4L
v[is.na(v)] <- "#N/A"
}else{
Expand Down
2 changes: 1 addition & 1 deletion R/writeData.R
Expand Up @@ -38,7 +38,7 @@
#' \item{\bold{slantDashDot}}{ slanted dash-dot border}
#' }
#' @param withFilter If \code{TRUE}, add filters to the column name row. NOTE can only have one filter per worksheet.
#' @param keepNA If \code{TRUE}, NA values are converted to #N/A in Excel else NA cells will be empty.
#' @param keepNA If \code{TRUE}, NA values are converted to #N/A in Excel else NA cells will be empty. If a string is passed, that string is used instead of "#N/A".
#' @param name If not NULL, a named region is defined.
#' @param sep Only applies to list columns. The separator used to collapse list columns to a character vector e.g. sapply(x$list_column, paste, collapse = sep).
#' @seealso \code{\link{writeDataTable}}
Expand Down
2 changes: 1 addition & 1 deletion R/writeDataTable.R
Expand Up @@ -16,7 +16,7 @@
#' @param tableName name of table in workbook. The table name must be unique.
#' @param headerStyle Custom style to apply to column names.
#' @param withFilter If \code{TRUE}, columns with have filters in the first row.
#' @param keepNA If \code{TRUE}, NA values are converted to #N/A in Excel else NA cells will be empty.
#' @param keepNA If \code{TRUE}, NA values are converted to #N/A in Excel else NA cells will be empty. If a string is passed, that string is used instead of "#N/A".
#' @param sep Only applies to list columns. The separator used to collapse list columns to a character vector e.g. sapply(x$list_column, paste, collapse = sep).
#' @param stack If \code{TRUE} the new style is merged with any existing cell styles. If FALSE, any
#' existing style is replaced by the new style.
Expand Down
6 changes: 3 additions & 3 deletions R/writexlsx.R
Expand Up @@ -47,7 +47,7 @@
#' between each column. If "\code{all}" all cell borders are drawn.}
#' \item{\bold{borderColour}}{ Colour of cell border}
#' \item{\bold{borderStyle}}{ Border line style.}
#' \item{\bold{keepNA}} {If \code{TRUE}, NA values are converted to #N/A in Excel else NA cells will be empty. Defaults to FALSE.}
#' \item{\bold{keepNA}} {If \code{TRUE}, NA values are converted to #N/A in Excel else NA cells will be empty. Defaults to FALSE. If a string is passed, that string is used instead of #N/A.}
#' }
#'
#' \bold{freezePane Parameters}
Expand Down Expand Up @@ -319,8 +319,8 @@ write.xlsx <- function(x, file, asTable = FALSE, ...){

keepNA <- FALSE
if("keepNA" %in% names(params)){
if(!"logical" %in% class(keepNA)){
stop("keepNA must be a logical.")
if(!"logical" %in% class(keepNA) && !"character" %in% class(keepNA)){
stop("keepNA must be a logical or a string.")
}else{
keepNA <- params$keepNA
}
Expand Down
2 changes: 1 addition & 1 deletion man/write.xlsx.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/writeData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/writeDataTable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.