Removing LinkingTo Packages After Installation

Junior R developer here. I'm really not clear on the meaning of the LinkingTo field in an R package's dependencies.

What I would like to do is remove the package BH after I've installed the packages that have LinkingTo dependencies on it (in particular, dplyr). The package takes up 154MB and my use case is very space sensitive (deploying R in an AWS Lambda). I've tried removing it and haven't seen any negative consequences, but I'd like to understand the implications more thoroughly.

I know that Writing R Extensions says

Specifying a package in ‘LinkingTo’ suffices if these are C++ headers containing source code or static linking is done at installation: the packages do not need to be (and usually should not be) listed in the ‘Depends’ or ‘Imports’ fields.

However, this seems to say multiple conflicting things to me and I'm not sure I completely understand the terms to begin with. If it's static linking done at install, that suggests to me that LinkingTo packages are really only needed while the dependent package is compiling and thereafter any necessary capabilities will be packaged into the dependent package. The other statement, "if these are C++ header containing source code", is more ambiguous and suggests possible runtime dependencies. Meanwhile, "the packages do not need to be (and usually should not be) listed in the ‘Depends’ or ‘Imports’ fields" suggests, given my limited understanding of the meaning of Depends and Imports, that these dependencies are generally not needed at runtime.

So, are LinkingTo dependencies needed at runtime or only at compile time? Once the dependent package is installed, can I simply remove them to save space? More specifically, can I safely remove BH once dplyr is installed without impacting dplyr's capabilities?

In well over my head here and hoping someone can provide some advice!

Just for additional context, I did explore the reverse dependencies on BH on my system and got the following

> tools::dependsOnPkgs("BH",dependencies=c("Enhances"))
> tools::dependsOnPkgs("BH",dependencies=c("Suggests"))
> tools::dependsOnPkgs("BH",dependencies=c("Depends"))
> tools::dependsOnPkgs("BH",dependencies=c("Imports"))
> tools::dependsOnPkgs("BH",dependencies=c("LinkingTo"))
[1] "dplyr"
> tools::dependsOnPkgs("BH",dependencies=c("all"))
 [1] "dplyr"       "glue"        "purrr"       "tibble"      "tidyr"      
 [6] "tidyselect"  "ps"          "stringr"     "usethis"     "callr"      
[11] "devtools"    "lubridate"   "processx"    "xopen"       "naptime"    
[16] "pillar"      "pkgbuild"    "rcmdcheck"   "sessioninfo" "fs"         
[21] "pkgload"     "remotes"     "rlang"      

I'm a little confused about the results here as well... because my understanding is that "all" = c("Enhances","Suggests","Depends","Imports","LinkingTo") and yet I get back more dependencies using that parameter...

If anyone even has any suggestions on how to figure this out, it would be helpful! I'm happy to do the reading and research, I'm just not sure how to get a conclusive answer on this!

For future reference,and regarding cross posting policy, this topic has also been post on github

1 Like

Further following up, the specific answer from the GitHub thread was:

romainfrancois commented on Feb 2

We'll eventually remove the BH dependency. In the meantime, yes, BH is only used for header files, so it should be safe to remove it.

The more general answer is probably that whether or not you can remove LinkingTo packages after installation is highly package dependent.