Dependency package “package_name” not available

后端 未结 4 1504
生来不讨喜
生来不讨喜 2021-01-17 20:40

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 organizatio

相关标签:
4条回答
  • 2021-01-17 20:46

    Brandon's solution did not work for me. However, I found that if one runs document after loading the package, then it doesn't throw an error. Also, even when it throws an error, it still seems to be updating the package. So one can work around it by running the 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"’
    
    0 讨论(0)
  • 2021-01-17 20:57

    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.

    0 讨论(0)
  • 2021-01-17 21:05

    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.

    0 讨论(0)
  • 2021-01-17 21:08

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

    0 讨论(0)
提交回复
热议问题