Bil Bal
Bil Bal

Reputation: 141

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?

Upvotes: 5

Views: 7108

Answers (2)

Thomas
Thomas

Reputation: 44585

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.

Upvotes: 7

Dirk is no longer here
Dirk is no longer here

Reputation: 368647

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.

Upvotes: 3

Related Questions