How do different versions of R manage to seemingly

2019-08-12 04:52发布

问题:

And can I exploit this to write a function or process that downloads packages (and package dependencies) for specific versions of R with only 1 R installation available?

Background

I work at a site with a number of R versions installed, primarily on Windows environments and machines. Some of these environments/machines are unable to connect to the internet, but users demand certain packages/libraries to be installed on them for use.

The versions of R I have available to me are not standardised. I cannot use install.packages() on an internet connected machine and manually transfer the resulting downloaded packages across to the non-connected machines, as the resulting versions of R/packages may be incompatible on the non-connected machine.

Let us accept that hunting and downloading all packages and dependencies manually at this scale is impossible. The demand for packages would be constant and changing and unable to be predicted ahead of time. I am not aware of a way to easily and automatically determine the version numbers for packages and dependencies that match to various versions of R without a painful manual trawl through the likes of CRAN package histories/archives. I know there does not appear to be an "Rversion=" argument to install.packages() or something similar. Most of the packages I've found that "kind-of" address package versioning either assume you already know what packages and versions you need or you already have them. The users are unable to provide me package/dependency version information: they just know they want a certain package named "X" on their computers, but I can find out what version of R they are running.

I would be tempted to say that my endeavour is quite hopeless...except...it appears to me that the different versions of R that can connect to CRAN ARE somehow downloading the packages that correspond to their own versions.

If I am wrong in this, please correct me. But if they are, then there is some method, function, or technique they are exploiting to do so...and I do not see, on the face of it, why I could not at least partially or theoretically exploit this same technique or mechanism if i could find out exactly what it was.

Alternate answers to my predicament (automatically downloading package/versions that correspond to various release versions of R), would also be appreciated if my line of inquiry appears fruitless.

The following are NOT valid solutions to my problem:

  • Upgrade/standardise your versions of R
  • Something requiring admin rights on multiple machines (i might be able to stretch this to one computer/environment)
  • Use linux
  • Make the users suck it up/get package versioning information/do it for themselves
  • Get internet/CRAN access to the non-internet-connected machines
  • Mirror CRAN locally

回答1:

This isn't an answer, but it is too long for a comment. If I understood correctly, an user can tell you that he wants the package X and you have to provide it to him. I guess that you can download somewhere the correct version and transfer the package to the user's machine.

This seems hard to do in general, but maybe doable. However, it requires a little cooperation from the user.

As already said in the comments, the package archive exists and has all the old versions of each package. Keep in mind that the following line:

installed.packages()

gives you all the packages installed on a machine. I don't think that this could be too much to ask to the user.

I'd proceed as follow.

  • Get to the archive page of the desired package.
  • Download the newest package source, unfold it and check the DESCRIPTION file.
  • From it, see if the package is compatible with the user's R version. If not, download the second-new and so on.
  • Check the fields Depends and Import of the DESCRIPTION file, to meet the dependencies and see if they are installed by examining the object returned by installed.packages() from the user's machine.
  • If a package is missing, go recursively to meet all the dependencies.
  • If you are done, now you need to compile each downloaded package (since archives seems to have just the source code, you need to compile it to distribute it to the user's machine).

All the above steps can be done by writing a simple function. It might be boresom to deal with all the exceptions, but I guess that it shouldn't be so hard to do the above in R (or in other programming languages, depending on your expertise).



回答2:

This is too long for a comment, but not a fully answer.

I'd second package archive. I think you're going to find that you need/want to install from source quite often. That might be wrong, but if true it means installing Rtools and devtools on each machine which may or may not be feasible.

To avoid installing Rtools everywhere, you might be able to do is have your internet connected machine store every version of R you might want to talk to, uninstall/reinstall Rtools as needed, compile, and then go into your packages directory and carry the compiled package to your destination computer.

Once you have devtools installed with the version of R (and Rtools) you are targeting, then I think you'll have something approaching a tenable situation. The one last step I can think of is that you might want to set up your own CRAN mirror and pull copies of the archive locally, to help the world, and lessen abuse on others mirrors.

From an internet/mirror connected machine on the right version of R you can examine the tree of versions of the package you want, start with the newest and work your way backwards running Rscript from the command line with devtools::install_version until you successfully install. From there it should be a simple matter of going into R

For other potentially useful tools see also:

  • sessionInfo
  • R.oo::getDescriptionFile