Issues using xlsx package to insert data from R to excel

前端 未结 2 1341
野趣味
野趣味 2021-01-12 20:57

I´m trying to create a new excel workbook from R to save a few small datasets using xlsx package. For some reason it was working fine, but i´m unable to do it again.

2条回答
  •  遥遥无期
    2021-01-12 21:48

    It is possible the problem is with Java, not XLConnect. Be sure you have Java installed by taking the test on the Java site -- it will confirm Java is correctly installed. Then make sure R knows the path to find the jre.dll or something like that file name for what is crucial.

    Second, here is the code I have been using for a year, without the error message you got. If it helps you ....

    read.xls <- function(filename, sheetnumber=1, sheetname=NULL, forceConversion=TRUE, startCol=0,  stringsAsFactors=TRUE) {
    wb <- loadWorkbook(filename)
    if (is.null(sheetname)) sheetname = getSheets(wb)[sheetnumber]
    df <- readWorksheet(wb, sheet=sheetname, forceConversion=forceConversion, startCol=startCol)
    if (stringsAsFactors) {
    ischar <- sapply(df, class) == "character"
    for (i in 1:length(df)) {
    if (ischar[i]) df[,i] <- factor(df[,i])
    }
    }
    df
    }
    

提交回复
热议问题