Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
860 views
in Technique[技术] by (71.8m points)

r - convert a csv to excel without using xlsx package

I want to convert a csv file to excel.

I found from the search in Internet that the best proposal it to use the library(xlsx) and use the write.xlsx(..) to write my dataframe to excel file.

However when I try to load and use the xlsx library and use it I receive the following:

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.

Is there any other way to convert the csv to excel or is there anyone faced the previous problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can do this in rio without needing a java dependency. It calls the openxlsx package.

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")

If you wanted to do this directly with openxlsx, you can run something like:

library("openxlsx")
write.xlsx(read.csv("mtcars.csv"), "mtcars.xlsx")

Full disclosure: I'm the author of rio.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...