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 '='
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: