Search code examples
rexport-to-excel

Wrong example in Package ‘xlsReadWrite’ pdf guide?


At the following link you can find the pdf guide of the xls.ReadWrite package

http://cran.r-project.org/web/packages/xlsReadWrite/xlsReadWrite.pdf

Running on R this code available at page 8 (xls.write function):

myval <- data.frame(
Fertility = c(80.2, 83.1, 92.5),
Agriculture = c(17, 45.1, 39.7),
Testlogical = c(TRUE, TRUE, FALSE),
Education = as.integer(c(12, 9, 5)),
Catholic = c(9.96, 84.84, 93.4),
Infant.Mortality = c(22.2, 22.2, 20.2),
Testcharacter = c("Co", "De", "Fr"), stringsAsFactors = FALSE)

# write the data.frame...
write.xls(myval, "mytest.xls")

... I get the following error:

Error in .Call("WriteXls", x, file, colNames, sheet, from - 1, rowNames,  : 
  Incorrect number of arguments (7), expecting 6 for 'WriteXls'

How can I explain this strange behaviour?


Solution

  • You need to run this after you install the package:

    xls.getshlib()
    

    Either one of two things will happen:

    1 - it will work and the package will work or 2 - it will complain you're not on a 32-bit OS and not work.

    If it worked, your write.xls should work fine. If not just export as a csv and save it as an excel file.