不同版本的R如何看似自动地从CRAN下载不同的适当软件包版本? [英] How do different versions of R manage to seemingly automatically download different appropriate package versions from CRAN?

查看:363
本文介绍了不同版本的R如何看似自动地从CRAN下载不同的适当软件包版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以利用它编写一个仅下载1个R安装版本即可下载特定版本R的软件包(和软件包依赖项)的函数或过程吗?

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?

背景

我在安装了多个R版本的站点上工作,主要是在Windows环境和计算机上.这些环境/机器中的某些无法连接到Internet,但是用户需要在其上安装某些软件包/库才能使用.

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.

我可以使用的R版本未标准化.我无法在已连接互联网的计算机上使用install.packages()并将手动下载的软件包手动传输到未连接的计算机,因为R/packages的最终版本可能在未连接的计算机上不兼容.

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.

让我们接受这样的规模,手动搜索和下载所有软件包和依赖项是不可能的.对包装的需求将是恒定不变的,并且无法提前预测.我不知道有一种方法可以轻松,自动地确定与R的各种版本相匹配的程序包和依赖项的版本号,而不会像CRAN程序包历史记录/归档那样费力地进行手动跟踪.我知道install.packages()或类似的东西似乎没有"Rversion =参数.我发现的大多数软件包都是同类"地址软件包的版本控制,它们假设您已经知道所需的软件包和版本,或者已经拥有它们.用户无法向我提供程序包/依赖版本信息:他们只是知道他们想要在计算机上安装一个名为"X"的程序包,但我可以知道他们正在运行的R版本.

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.

我很想说我的努力是没有希望的……除了……在我看来,可以连接到CRAN的R的不同版本都以某种方式下载了与自己版本相对应的软件包.

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.

如果我的询问行不通,那么我的困境的替代答案(自动下载与R的各个发行版本相对应的软件包/版本)也将不胜感激.

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.

以下不是解决我问题的有效方法:

  • 升级/标准化您的R版本
  • 需要多台计算机上的管理员权限的事物(我也许可以将其扩展到一台计算机/环境中)
  • 使用linux
  • 让用户自己吸吮/获取软件包版本信息/自己动手
  • 获得对非互联网连接机器的Internet/CRAN访问权限
  • 本地镜像CRAN

推荐答案

这不是答案,但是评论太长.如果我理解正确,那么用户可以告诉您他需要软件包X,而您必须将其提供给他.我想您可以下载正确版本的某个地方,然后将软件包传送到用户的计算机上.

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.

  • 转到所需软件包的存档页面.
  • 下载最新的软件包源,将其展开并检查DESCRIPTION文件.
  • 从中查看软件包是否与用户的R版本兼容.如果不是,请下载第二个新版本,依此类推.
  • 检查DESCRIPTION文件的字段DependsImport,以满足相关性,并通过检查installed.packages()从用户计算机返回的对象来查看它们是否已安装.
  • 如果缺少软件包,请递归去满足所有依赖项.
  • 完成后,现在您需要编译每个下载的软件包(由于归档文件似乎只有源代码,因此您需要对其进行编译以将其分发到用户的计算机上).
  • 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).

以上所有步骤都可以通过编写一个简单的函数来完成.处理所有异常可能很无聊,但我想用R(或其他编程语言,具体取决于您的专业知识)来完成上述工作应该并不难.

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).

这篇关于不同版本的R如何看似自动地从CRAN下载不同的适当软件包版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆