Skip to content

Commit

Permalink
Merge pull request #360 from deschen1/na_handling_loadWorkbook
Browse files Browse the repository at this point in the history
Fixes #72 by adding an optional argument na.convert
  • Loading branch information
JanMarvin authored Jun 29, 2022
2 parents 4f14a99 + 7a0219f commit 547640d
Show file tree
Hide file tree
Showing 8 changed files with 468 additions and 153 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# openxlsx (development version)

## Fixes

* Fixed warning on `dataValidation(..., type = "list")` ([#342](https://github.com/ycphs/openxlsx/issues/342))

## Improvements

* Added optional argument to `loadWorkbook` to decide if empty/blank cells should be converted to NA_character_ (the default) or left blank as is
* Improve detectDates ([#288](https://github.com/ycphs/openxlsx/issues/288))
* Add type blanks and not blanks to conditional formatting ([#311](https://github.com/ycphs/openxlsx/pull/311))

Expand Down
7 changes: 5 additions & 2 deletions R/loadWorkbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' @param file A path to an existing .xlsx or .xlsm file
#' @param xlsxFile alias for file
#' @param isUnzipped Set to TRUE if the xlsx file is already unzipped
#' @param na.convert Should empty/blank cells be converted to `NA_character_`. Defaults to TRUE.
#' @description loadWorkbook returns a workbook object conserving styles and
#' formatting of the original .xlsx file.
#' @return Workbook object.
Expand All @@ -25,7 +26,7 @@
#' saveWorkbook(wb, "loadExample.xlsx", overwrite = TRUE)
#' }
#'
loadWorkbook <- function(file, xlsxFile = NULL, isUnzipped = FALSE) {
loadWorkbook <- function(file, xlsxFile = NULL, isUnzipped = FALSE, na.convert = TRUE) {

## If this is a unzipped workbook, skip the temp dir stuff
if (isUnzipped) {
Expand Down Expand Up @@ -264,7 +265,9 @@ loadWorkbook <- function(file, xlsxFile = NULL, isUnzipped = FALSE) {
vals <- getNodes(xml = sharedStrings, tagIn = "<si>")

if ("<si><t/></si>" %in% vals) {
vals[vals == "<si><t/></si>"] <- "<si><t>NA</t></si>"
if (na.convert){
vals[vals == "<si><t/></si>"] <- "<si><t>NA</t></si>"
}
Encoding(vals) <- "UTF-8"
attr(vals, "uniqueCount") <- uniqueCount - 1L
} else {
Expand Down
Binary file added inst/extdata/na_convert.xlsx
Binary file not shown.
4 changes: 3 additions & 1 deletion man/loadWorkbook.Rd

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

34 changes: 22 additions & 12 deletions revdep/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,65 @@

|field |value |
|:--------|:----------------------------|
|version |R version 4.1.2 (2021-11-01) |
|version |R version 4.1.3 (2022-03-10) |
|os |Ubuntu 18.04.6 LTS |
|system |x86_64, linux-gnu |
|ui |X11 |
|language |(EN) |
|collate |C.UTF-8 |
|ctype |C.UTF-8 |
|tz |UTC |
|date |2022-02-08 |
|date |2022-03-20 |
|pandoc |2.7.3 @ /usr/bin/pandoc |

# Dependencies

|package |old |new |Δ |
|:--------|:-----|:----------|:--|
|openxlsx |4.2.5 |4.2.5.9000 |* |
|Rcpp |1.0.8 |1.0.8 | |
|stringi |1.7.6 |1.7.6 | |
|zip |2.2.0 |2.2.0 | |
|package |old |new |Δ |
|:--------|:-------|:----------|:--|
|openxlsx |4.2.5 |4.2.5.9000 |* |
|Rcpp |1.0.8.3 |1.0.8.3 | |
|stringi |1.7.6 |1.7.6 | |
|zip |2.2.0 |2.2.0 | |

# Revdeps

## Failed to check (25)
## Failed to check (35)

|package |version |error |warning |note |
|:--------------|:-------|:-----|:-------|:----|
|appreci8R |? | | | |
|artMS |? | | | |
|bibliometrix |3.2.1 |1 | | |
|BoneProfileR |? | | | |
|breakaway |? | | | |
|bruceR |? | | | |
|cbaf |? | | | |
|CHRONOS |? | | | |
|CNVPanelizer |? | | | |
|CoTiMA |? | | | |
|DAPAR |? | | | |
|ddPCRclust |? | | | |
|Ecfun |? | | | |
|fedup |? | | | |
|GA4GHshiny |? | | | |
|genekitr |? | | | |
|hypeR |1.10.0 |1 | | |
|isoreader |? | | | |
|maEndToEnd |? | | | |
|MatrixQCvis |? | | | |
|MicroSEC |? | | | |
|MSEtool |? | | | |
|nanotatoR |? | | | |
|openPrimeR |? | | | |
|parameters |? | | | |
|Pigengene |? | | | |
|PloGO2 |? | | | |
|rbiom |? | | | |
|sangeranalyseR |1.4.0 |1 |1 |2 |
|RIPAT |? | | | |
|sangeranalyseR |? | | | |
|SEtools |? | | | |
|sigFeature |? | | | |
|struct |? | | | |
|structToolbox |? | | | |
|TarSeqQC |? | | | |
|TPP |3.22.1 |1 | |3 |
|uncoverappLib |? | | | |

2 changes: 1 addition & 1 deletion revdep/cran.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## revdepcheck results

We checked 138 reverse dependencies (0 from CRAN + 138 from Bioconductor), comparing R CMD check results across CRAN and dev versions of this package.
We checked 141 reverse dependencies (0 from CRAN + 141 from Bioconductor), comparing R CMD check results across CRAN and dev versions of this package.

* We saw 0 new problems
* We failed to check 0 packages
Expand Down
Loading

0 comments on commit 547640d

Please sign in to comment.