I am trying to import an excel sheet into r. I used the following code:
x <- loadWorkbook("x.xlsx")
b <- readWorksheet(x, sheet="b")
The first line works fine, however, running the second gives the following error:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘readWorksheet’ for signature ‘"jobjRef", "character"’
I have no missing values in that sheet.
For the purpose of reproducing, download trial.xlsx
from https://github.com/ahmedfsalhin/1stpaper.
system info: Yosemite operating system.
After lot of struggle found the solution to this. In R studio go to the packages and remove all the packages related to XLConnect and xlsx. Then instal only XLConnect packages by typing
After this the issue should not exist.
I had the same problem while testing out three different packages for loading .xlsx files into R (XLConnect, xlsx, gdata). The solution was to specify the namespace for
loadWorkbook
:Then it works, no matter if xlsx is loaded/installed or not. The error is because there is also a function with the same name in xlsx and it is defaulting to using the wrong one, which depends on the order the packages were loaded.
It appears the "root cause" is that you should add code to specify both the function and the package it belongs to. Type
XLConnect::loadWorkbook
to select the one you want in this case. There's no 'confusion,' or random selection of duplicated function names inR
. The choice depends on the load order of all loaded packages. Usesearch()
to see the order in which packages are checked for the command you've entered.E.g., at present I get
You'll notice that anything in your environment (
.GlobalEnv
) is selected first, and that all loaded libraries override thebase
package, for example.Try this instead x <- readWorksheetFromFile("x.xlsx") in XLConnenct package.