1.2 writexl
截止到2021年5月17日,writexl包功能比较简单,仅有输出Excel功能。快速、不依赖java和Excle是它绝对的优势,并且输出文件相比openxlsx
包较小。
1.2.1 用法
安装
install.packages("writexl")
参数
write_xlsx(
x,path = tempfile(fileext = ".xlsx"),
col_names = TRUE,
format_headers = TRUE,
use_zip64 = FALSE
)
输出Excel
library(writexl)
::write_xlsx(iris,path = 'iris.xlsx')
writexlwrite_xlsx(list(mysheet1 = iris,mysheet2 = iris),path = 'iris.xlsx')
效率比较
library(microbenchmark)
library(nycflights13)
microbenchmark(
writexl = writexl::write_xlsx(flights, tempfile()),
openxlsx = openxlsx::write.xlsx(flights, tempfile()),
times = 2
)
文件大小比较
::write_xlsx(flights, tmp1 <- tempfile())
writexlfile.info(tmp1)$size
::write.xlsx(flights, tmp2 <- tempfile())
openxlsxfile.info(tmp2)$size
其它功能
<- data.frame(
df name = c("UCLA", "Berkeley", "Jeroen"),
founded = c(1919, 1868, 2030),
website = xl_hyperlink(c("http://www.ucla.edu", "http://www.berkeley.edu", NA), "homepage")
)$age <- xl_formula('=(YEAR(TODAY()) - INDIRECT("B" & ROW()))')
dfwrite_xlsx(df, 'universities.xlsx')
# cleanup
unlink('universities.xlsx')