openxlsx in its current version 4.2.4 overwrites digits precision from default 7 to 22. This results in unexpected behavior, if you try to write a lazy evaluating data.frame using writeData.
library(openxlsx)
library(magrittr)
library(dplyr)
wb <- createWorkbook()
sheet <- addWorksheet(wb,"Sheet")
data.frame(a=55.7) %>% mutate(a=a%>%format(nsmall=1)) %>% writeData(wb,sheet,.)
saveWorkbook(wb,"test.xlsx")
You may see, that the workbook contains not the expected string "55.7", but more decimals. This is because in global environment format works with 7 digits, so format(55.7)=="55.7", but within writeData it evaluates as
format(55.7)=="55.700000000000003"
This is not a issue of floating-point math, but an issue of changing environments. format uses as a default value "digits=getOption("digits")". Default is 7, within writeData it's 22. That's all there is, nothin special about that.
I wanted to know, why format(55.7) does not get evaluated within the context of global environment.