不使用xlsx软件包将csv转换为excel

Bil*_*Bal 5 r

我想将csv文件转换为excel。

从Internet上的搜索中,我发现最好的建议是使用库(xlsx)并使用write.xlsx(..)将数据框写入excel文件。

但是,当我尝试加载并使用xlsx库并使用它时,会收到以下消息:

Loading required package: rJava
Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: inDL(x, as.logical(local), as.logical(now), ...)
  error: unable to load shared object 'C:/Users/Ban/Documents/R/win-library/3.1/rJava/libs/x64/rJava.dll':
  LoadLibrary failure:  Could not find the specified mode. unit.
Run Code Online (Sandbox Code Playgroud)

还有其他方法可以将csv转换为excel,还是有人遇到过以前的问题?

Tho*_*mas 5

您可以在rio中执行此操作,而无需Java依赖项。它调用openxlsx包。

install_github("leeper/rio")
library("rio")

# create an example CSV
export(mtcars, "mtcars.csv")

# convert the CSV to Excel (.xlsx)
convert("mtcars.csv", "mtcars.xlsx")
Run Code Online (Sandbox Code Playgroud)

如果您想直接使用openxlsx进行此操作,则可以运行以下命令:

library("openxlsx")
write.xlsx(read.csv("mtcars.csv"), "mtcars.xlsx")
Run Code Online (Sandbox Code Playgroud)

完全披露:我是rio的作者。


Dir*_*tel 3

对 CRAN 的至少研究揭示了一些软件包:

  • XLconnect需要 Java
  • xlsx需要 Java
  • openxlsx不需要 Java,但更年轻并且没有广泛使用
  • writexls在大多数系统的底层使用 Perl。