You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
write_excel_csv inserts 'U+FEFF', Byte Order Mark (BOM) when append = TRUE, write_csv doesn't. I believe it would be preferable if neither did.
From the docs:
All columns are encoded as UTF-8. write_excel_csv() and write_excel_csv2() also include a UTF-8 Byte order mark which indicates to Excel the csv is UTF-8 encoded.
However, write_excel_csv doesn't include the BOM if there is no "append"ing.
I discovered this problem because a vlookup in Excel wasn't matching the values in the first row of each appended section.
I've included session info, but can confirm that this behavior is the same on Windows and Mac.
Note: reprex creates 2 csv files that are necessary to demonstrate problem.
library(reprex)
library(tidyverse)
simple_tbl<- tibble(
Region= c("West", "East", "North", "South"),
Sales= c(50, 100, 73, 28)
)
simple_write<-function(rgn, sales, out_file, use_excel_csv) {
out<- tibble(
region_summary= paste0("Sales for the ", rgn, " region: ", sales)
)
append_flag<- file.exists( out_file )
if (use_excel_csv) {
write_excel_csv(
out,
out_file,
append=append_flag,
col_names=!append_flag
)
} else {
write_csv(
out,
out_file,
append=append_flag,
col_names=!append_flag
)
}
}
# sales_excel.csv will have U+FEFF (Byte Order Mark)# at start of each "append"simple_tbl %>%
select(Region, Sales) %>%
pwalk(~simple_write(..1, ..2, "sales_excel.csv", TRUE))
# sales_no_excel.csv will not have any U+FEFFsimple_tbl %>%
select(Region, Sales) %>%
pwalk(~simple_write(..1, ..2, "sales_no_excel.csv", FALSE))
Thanks, better example. But why close? Any comments on the underlying issue? If the intent is to create files for Excel to read, then the current functionality will create data that looks ok, but will not be treated as one would expect in Excel.
write_excel_csv
inserts 'U+FEFF', Byte Order Mark (BOM) when append = TRUE,write_csv
doesn't. I believe it would be preferable if neither did.From the docs:
However,
write_excel_csv
doesn't include the BOM if there is no "append"ing.I discovered this problem because a vlookup in Excel wasn't matching the values in the first row of each appended section.
I've included session info, but can confirm that this behavior is the same on Windows and Mac.
Note: reprex creates 2 csv files that are necessary to demonstrate problem.
Created on 2020-02-07 by the reprex package (v0.3.0)
Session info
The text was updated successfully, but these errors were encountered: