ropensci / writexl

Portable, light-weight data frame to xlsx exporter for R
https://docs.ropensci.org/writexl
Other
210 stars 17 forks source link

'xl_formula' fails when there are any NAs in otherwise valid vector #40

Closed mir-cat closed 5 years ago

mir-cat commented 5 years ago

xl_formula checks that all values in the vector start with an '=' to ensure that every value is a valid formula. However, if there are any NAs in the vector, even if every non na value starts with '=', the function call fails. Manually setting the class of a column to "c('xl_formula', 'xl_object)" has the behavior that all NAs are blank in the excel output, which to me seems to be the desired behavior.

I think this could be fixed by adding 'na.rm = T' to the 'all' call that checks for '=' at the start of every value.

reprex below:


formula <- paste0('=A', seq_len(5))

writexl::xl_formula(formula)
#>  [:xl_formula:]
#> =A1
#> =A2
#> =A3
#> =A4
#> =A5

formula[1] <- NA

writexl::xl_formula(formula)
#> Error in writexl::xl_formula(formula): Formulas must start with '='