Dependency package “package_name” not available

∥☆過路亽.° 提交于 2019-12-01 15:53:50

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"’

Unselecting the circled option in Project Options > Build Tools dialogue solves this problem, although I'm not quite clear on why:

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.

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!