John Smith John Smith - 1 month ago 15
R Question

Using XLConnect to read in xls

I'm using the following code to try and read in an old


path <- "C:/Users/foo/Desktop/WEEK 17.xls"
df <- readWorksheet(path, sheet = 1)

i get the following error

Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘readWorksheet’ for signature ‘"character", "numeric"’

Does anyone know why?
I can open the file in excel


It s because readWorksheet use workbook as object.

You have to

# Load workbook
wb <- loadWorkbook("C:/Users/foo/Desktop/WEEK 17.xls")

and then

df <- readWorksheet(wb, sheet = 1)

or use readWorksheetFromFile("C:/Users/foo/Desktop/WEEK 17.xls", sheet = 1)

Which realy do the same

> XLConnect::readWorksheetFromFile
function (file, ...) 
    args <- list(...)
    args$object <- loadWorkbook(file, create = FALSE)"readWorksheet", args)
<environment: namespace:XLConnect>