问题
I am creating my own package. I am using a lot of existing packages in it and they work. I am using the same procedure for the xlsx package but it doesn't work. I have xlsx in Imports: in my DESCRIPTION file. I have @import xlsx in my respective .R file. I also tried @importFrom write.xlsx for a particular function with the same result. I am using libraries devtools and roxygen2 for creating the package. My new package is build, but if I proceed Check, an error occurs:
Installation failed.
See 'C:/Work/Package/MyPackage.Rcheck/00install.out' for details.
* DONE
Status: 1 ERROR
Warning: running command '"C:/R/R-3.3.3/bin/x64/Rcmd.exe" INSTALL -l "C:/Users/Work/Package/MyPackage.Rcheck" --no-html "C:\Users\Work\Package\MyPackage.Rcheck\00_pkg_src\MyPackage"' had status 1
and
checking whether package 'MyPackage' can be installed ... ERROR
Installation failed.
See 'C:/Users/Work/Package/MyPackage.Rcheck/00install.out' for details.
R CMD check results
But there is no .out file from the error. The whole file MyPackage.Rcheck occurs for a short time during the checking process, but then it disappears. So I am not able to check the .out file and find an error.
I also tried to use command library(xlsx) inside my code. In this situation the process of building and checking has less problems. There is only one warning and one note:
WARNING
'library' or 'require' call not declared from: 'xlsx'
'library' or 'require' call to 'xlsx' in package code.
Please use :: or requireNamespace() instead.
See section 'Suggested packages' in the 'Writing R Extensions' manual.
NOTE
MyFunction: no visible global function definition for 'write.xlsx'
But I know that if I would like to upload my code to the CRAN there should not be any warnings.
I also know that xlsx package has two dependencies: rJava and xlsxjars. If I put them to Imports: in DESCRIPTION file and also use the @import in my .R file the same problem appears. I also tried used Depends: with the same results.
Thank you all for your help.
回答1:
By disabling RStudio option "Cleanup output after successful R CMD check" I found the .out file. The problem was in Java on my computer. I am using 64-bit version of R and I have also 64-bit version of Java. So the package xlsx normally worked. But I have also installed 32-bit version of R on my computer but there was no 32-bit version of Java. After installing it, everything works. Every version of R must have the same version of Java. An oppositely, there must not be Java version without R opposite.
回答2:
I had the same issue over and over running in a Linux environment without the usage of Rstudio.
My issue was @importFrom xlsx read.xlsx, removing this and adding a call xlsx::read.xlsx('myFile.xlsx', 1) in the code where read.xlsx is used, then running R -e "devtools::document() works properly. After this, I've added again @importFrom xlsx read.xlsx and removed the xlsx:: and then is working just fine.
I think this could be something related to first setting up configurations from xlsx package since before doing this I never made a call from it.
来源:https://stackoverflow.com/questions/43738366/r-importing-xlsx-package-to-my-own-package-doesnt-work