问题
I'm getting a strange error when trying to build and reload in RStudio. In my description file I've included a package that I have built and maintain within my organization. It's not on CRAN. Essentially, when I update the DESCRIPTION file (Depends: ...), I get this error:
==> devtools::document(roclets=c('rd', 'collate', 'namespace', 'vignette'))
Updating fczstudy documentation
Loading fczstudy
Error in (function (dep_name, dep_ver = NA, dep_compare = NA) :
Dependency package surv3 not available.
Calls: suppressPackageStartupMessages ... <Anonymous> -> load_all -> load_depends -> mapply -> <Anonymous>
Execution halted
In this case, surv3
is a package that I maintain within my organization - I can confirm that it is indeed installed because I'm using it.
This doesn't seem to happen with other packages from CRAN. It just started a few days ago. It's not allowing me to import my package (surv3)
I'm really not sure how to debug this.
traceback()
in the console after ctrl+shift+B returns nothing
Here is my sessionInfo()
:
R version 3.2.0 (2015-04-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] surv3_1.01 knitr_1.11 fczstudy_0.1.0 dplyr_0.4.3
[5] ggplot2_1.0.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.1 assertthat_0.1 digest_0.6.8
[4] MASS_7.3-40 R6_2.1.1 grid_3.2.0
[7] plyr_1.8.3 gtable_0.1.2 DBI_0.3.1
[10] magrittr_1.5 scales_0.3.0 stringi_0.5-5
[13] lazyeval_0.1.10 reshape2_1.4.1 rmarkdown_0.8.1
[16] proto_0.3-10 tools_3.2.0 stringr_1.0.0
[19] munsell_0.4.2 yaml_2.1.13 parallel_3.2.0
[22] colorspace_1.2-6 htmltools_0.2.6
回答1:
Brandon's solution did not work for me. However, I found that if one runs document
after loading the packing, then it doesn't throw an error. Also, even when it throws the error, it still seems to be updating the package. So one can work around it by running code in another order.
I looked into the source code for the document
function and tracked down the error message to a requireNamespace
call. Turns out that the package was not missing at all, but it had an error in the .onLoad
function call. This causes requireNamespace
to return FALSE
(package could not be loaded), same as if the package is not installed. So, the real issue is that the error message from document
is incorrect in this particular case.
Example error:
Browse[2]> requireNamespace("thepackage")
Loading required namespace: thepackage
Failed with error: ‘.onLoad failed in loadNamespace() for 'thepackage', details:
call: some_function(., some_variable)
error: could not find function "some_function"’
回答2:
Unselecting the circled option in Project Options > Build Tools dialogue solves this problem, although I'm not quite clear on why:
回答3:
When I had the same problem, it was caused by a problem in the DESCRIPTION file.
The line starting with Depends:
had the dependency package listed in the wrong case (e.g. Ggplot2
instead of ggplot2
)
I hope you don't need this fix anymore, but it might be useful for someone else.
回答4:
Another possible solution is to check if the package dependencies are up to date. I have the same problem with ggplot2, and when I tried to load the package, an error occurred because of the dependency package 'scales' was built in an R version with different internals. So the solution was to reinstall package scales.
So, you could try to reinstall all dependencies of the 'ggplot2' package.
来源:https://stackoverflow.com/questions/33428055/dependency-package-package-name-not-available