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

keepNA doesn't work when using write_xlsx #373

Closed
Tracked by #374
rowrowrowyourboat opened this issue Oct 11, 2022 · 3 comments
Closed
Tracked by #374

keepNA doesn't work when using write_xlsx #373

rowrowrowyourboat opened this issue Oct 11, 2022 · 3 comments

Comments

@rowrowrowyourboat
Copy link

When using write_xlsx and using the option keepNA, it doesn't seem to make a difference in the file output. Example code below shows using keepNA = FALSE and the output file showing #N/A's in the xlsx file.

testna.xlsx

library(openxlsx2)

a = 1:5
b = c(1:4,NA)

testdf<- cbind(a,b)

print(testdf)
#>      a  b
#> [1,] 1  1
#> [2,] 2  2
#> [3,] 3  3
#> [4,] 4  4
#> [5,] 5 NA

openxlsx2::write_xlsx(testdf, "testna.xlsx", keepNA = FALSE)

sessionInfo()
#> R version 4.2.1 (2022-06-23 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 22621)
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=English_United States.utf8 
#> [2] LC_CTYPE=English_United States.utf8   
#> [3] LC_MONETARY=English_United States.utf8
#> [4] LC_NUMERIC=C                          
#> [5] LC_TIME=English_United States.utf8    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] openxlsx2_0.3
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.9      withr_2.5.0     digest_0.6.29   R6_2.5.1       
#>  [5] lifecycle_1.0.3 magrittr_2.0.3  reprex_2.0.2    evaluate_0.17  
#>  [9] zip_2.2.1       highr_0.9       stringi_1.7.8   rlang_1.0.6    
#> [13] cli_3.4.1       rstudioapi_0.14 fs_1.5.2        rmarkdown_2.17 
#> [17] tools_4.2.1     stringr_1.4.1   glue_1.6.2      xfun_0.33      
#> [21] yaml_2.3.5      fastmap_1.1.0   compiler_4.2.1  htmltools_0.5.3
#> [25] knitr_1.40

Created on 2022-10-11 with reprex v2.0.2

@JanMarvin
Copy link
Owner

Hi @rowrowrowyourboat , thanks for the report. Is that supposed to act as complete.cases()?

@jmbarbone
Copy link
Collaborator

@JanMarvin , I think keepNA can be removed from the documentation. It's listed as an argument passed tp write_dtata/write_datatable but doesn't exist within them. I don't see it passed to any functions in the write_xlsx() call. We should remove it and add a note that invalid parameters in ... are silently ignored.

@rowrowrowyourboat , the proper argument for controlling NA values would be na.strings (through $add_data()

@rowrowrowyourboat
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants