Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert a csv to excel without using xlsx package

Tags:

r

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?

like image 225
Bil Bal Avatar asked Mar 21 '15 17:03

Bil Bal


2 Answers

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.

like image 150
Thomas Avatar answered Nov 11 '22 14:11

Thomas


A minimum of research on CRAN reveals a number of packages:

  • XLconnect needs Java
  • xlsx needs Java
  • openxlsx does NOT need Java but is younger and not as widely used
  • writexls uses Perl under the hood which most system have.
like image 35
Dirk Eddelbuettel Avatar answered Nov 11 '22 13:11

Dirk Eddelbuettel