Skip to content
Prev 61132 / 63424 Next

tools:: extracting pkg dependencies from DCF

Hi Jan,
On Fri, Oct 28, 2022 at 1:57 PM Jan Gorecki <j.gorecki at wit.edu.pl> wrote:

            
Really what you're looking for though, is to install all the dependencies
which aren't present right? Excluding base packages is just a particular
way to do that under certain assumptions about the CI environment.

So


needed_pkgs <- setdiff(package_dependencies(...),
installed.packages()[,"Package"])
install.packages(needed_pkgs, repos = fancyrepos)


will do what you want without installing the package itself, if that is
important. This will filter out base and recommended packages (which will
be already installed in your CI container, since R is).


Now this does not take into account versioned dependencies, so it's not
actually fully correct (whereas installing the package is), but it gets you
where you're trying to go. And in a clean CI container without cached
package installation for the deps, its equivalent.


Also, as an aside, if you need to get the base packages, you can do

installed.packages(priority="base")[,"Package"]

       base    compiler    datasets    graphics   grDevices        grid

     "base"  "compiler"  "datasets"  "graphics" "grDevices"      "grid"

    methods    parallel     splines       stats      stats4       tcltk

  "methods"  "parallel"   "splines"     "stats"    "stats4"     "tcltk"

      tools       utils

    "tools"     "utils"

(to get base and recommended packages use 'high' instead of 'base')

No need to be reaching down into unexported functions. So if you *really*
only want to exclude base functions (which likely will give you some
protection from versioned dep issues), you can change the code above to

needed_pkgs <- setdiff(package_dependencies(...),
installed.packages(priority = "high")[,"Package"])
install.packages(needed_pkgs, repos = fancyrepos)

Best,
~G