简体   繁体   English

如何在旧的不兼容版本的R上安装新的R包

[英]How to install a new R package on old, incompatible version of R

I am forced to use R 3.2.2 due to IT requirements at my company. 由于公司的IT要求,我被迫使用R 3.2.2。 I need to use a few packages that technically require R > 3.2.2 (chiefly prophet version 2 or greater). 我需要使用一些技术上要求R> 3.2.2的软件包(主要是2版或更高版本)。 I know that sometimes it is possible to "trick" the package into running in the older, incompatible version of R but I am unsure how to do this. 我知道有时可以“欺骗”该程序包使其在较旧的,不兼容的R版本中运行,但是我不确定如何执行此操作。

I downloaded the package using a newer version of R, then adjusted the description file as suggested by Patrick here ( How to install an R package to R-3.3.0 from GitHub, which is built on R-3.4.0? ), and moved the package file into the R 3.2.2 library path but it didn't work. 我使用较新版本的R下载了该软件包,然后按照Patrick在这里建议的那样调整了描述文件( 如何从基于R-3.4.0构建的GitHub将R软件包安装到R-3.3.0? ),以及将软件包文件移到了R 3.2.2库路径中,但是没有用。 I get the error "Error: This is R 3.2.2, package 'prophet' needs >= 3.2.3." 我收到错误“错误:这是R 3.2.2,程序包'prophet'需要> = 3.2.3”。

Does anyone have ideas/suggestions? 有人有想法/建议吗? Thank you! 谢谢!

Up front: @prosoitos' comment about using older versions of packages is likely your best bet, if you can find them. 预先说明:@prosoitos关于使用较旧版本软件包的评论可能是最好的选择,如果可以找到的话。 I believe that MRAN claims to have daily versions of all packages going back quite a ways, along with the checkpoint package for freezing the state of packages for your project. 我相信MRAN声称所有软件包的日常版本都可以追溯到很长时间 ,还有checkpoint软件包可以冻结项目的软件包状态。 In fact, try using that package, it might make several of the below "tricks" (please don't use them casually) unnecessary. 实际上,尝试使用该程序包,可能会使以下几个“技巧”(请不要随便使用它们)变得不必要。


It is true that some packages may "falsely require R versions", instead conveniently choosing the version of R the developer is using and/or an arbitrary version they copied from another package. 确实有些软件包可能“错误地要求R版本”,而是方便地选择开发人员正在使用的R版本和/或从其他软件包复制的任意版本。 However: 然而:

  1. There is no way for you to know if it is a true requirement without knowing the internals of the package code. 在不了解软件包代码内部的情况下,您无法知道是否是真正的要求。

    If the developer is conscientiously using appropriately-defined R version requirements, you can go through the commit history of the package (assuming github, gitlab, or some other accessible version control) and find when the R version changed in DESCRIPTION , and look at the previous commit(s) to see what change suggested the version increase. 如果开发人员认真地使用适当定义的R版本要求,则可以浏览包的提交历史记录(假设github,gitlab或其他一些可访问的版本控件),并在DESCRIPTION查找R版本的更改时间,然后查看以前的提交以查看哪些更改建议版本增加。 If you're lucky, the commit messages themselves will say something like "add argument xyz=, requiring newer R" , but that's not guaranteed or even likely, I suspect. 如果幸运的话,提交消息本身会说类似“添加参数xyz =,要求使用新的R”之类的字词 ,但是我怀疑这并不能保证,甚至不可能。

  2. Lacking that, there might be one function (legacy or new) that requires the newer version of R, but nothing else was changed. 缺少这一点,可能有一个功能(旧版或新版)需要R的较新版本,但没有其他更改。 This seems plausible to me, and again might require some sleuthing to confirm. 在我看来,这似乎是合理的,并且可能还需要进行一些侦查才能确认。

  3. Even if you find this, it is likely that it depends on other packages that have similarly-defined version requirements. 即使您发现了此问题,也可能取决于具有类似定义的版本要求的其他软件包。 So even if you figure things out for one package, it may cascade into several or dozens of packages. 因此,即使您为一个程序包解决了问题,它也可能会级联成几个或几十个程序包。 (Hint: perhaps checkpoint is looking better, as it helps with this.) (提示:也许checkpoint看起来更好,因为它对此有所帮助。)

If you somehow determine that either (a) you know that the R-version requirement is wrong, or (b) you know what it requires and you're willing to live without those arguments or functions, then: 如果您以某种方式确定(a)您知道R版本要求是错误的,或者(b)您知道其要求是什么,并且您愿意在没有这些参数或函数的情况下生活,那么:

  1. Clone or download the source; 克隆或下载源代码;
  2. Edit DESCRIPTION and change the R version, and I suggest you change the package version number as well so that you know which version you are using; 编辑DESCRIPTION并更改R版本,建议您也更改软件包的版本号,以便知道所使用的版本。 and you should note the version requirements for other packages, too, as it may hint at API changes, etc; 并且您还应该注意其他软件包的版本要求,因为这可能暗示API发生了更改等; and
  3. Build/install the local version. 生成/安装本地版本。

But ... there might be nuances to the code (and/or example code in documentation) that will not work in the older version. 但是...可能会有细微差别的代码(和/或文档中的示例代码)在旧版本中不起作用。 AND, what works for one package will not necessarily work for another. 而且,对一个软件包有效的方法不一定对另一个软件包有效。

This is a true case of caveat emptor. 这是买权人的真实情况。 The risk of code breaking is high. 代码破解的风险很高。 The likelihood of having to do this manual process for several packages is high. 必须对多个程序包执行此手动过程的可能性很高。 The likelihood that it all works the first time is low. 第一次全部起作用的可能性很小。

(Of course, you could always reach out to the developer/maintainer to ask.) (当然,您可以随时与开发人员/维护人员联系。)

It is not the exact answer to your question. 这不是您问题的确切答案。 But did you hear about conda package manager (which is universal to programming languages and many other system-relevant programs)? 但是您是否听说过conda软件包管理器(它对于编程语言和许多其他与系统相关的程序是通用的)?

You could resolve your headache - without admin rights - by locally installing higher versions of R into a virtual conda environment - and have it and run it in a virtual environment. 您可以通过在虚拟conda环境中本地安装更高版本的R,并在虚拟环境中运行它来解决头痛(无需管理员权限)。

To learn to use conda use Corey Schafer's tutorials are very good - and teaches you conda within merely 12 min ... . 要学习使用conda,请使用Corey Schafer的教程非常好-并在12分钟内教会您conda...。 Anaconda is just a variant, but I use miniconda - the produre and the command is the same. Anaconda只是一个变体,但我使用miniconda-产品和命令是相同的。

# install miniconda on linux 64 bit on python 3.7 background
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh

# linux 32 bit python 3.7
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86.sh
bash Miniconda3-latest-Linux-x86.sh

# windows 64 bit python 3.7
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Windows-x86_64.exe
# and run it 

# windows 32 bit python 3.7
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Windows-x86.exe
# and run it

# other combinations and conditions and operating systems and python 2.7
# https://conda.io/miniconda.html

# after installation, in terminal, conda is available from 
# wherever you are.
# create conda environment for R-3.5.1 the newest
conda create --name R351
# enter the virtual environment
source activate R351
# install R-3.5.1
conda install -c r r-base
# start R
R
# quit R and quit the environment
source deactivate

I searched long for version problems like this. 我长时间搜索了这样的版本问题。 And this was the cleanest solution ... 这是最干净的解决方案...

But actually also without conda, you can just locally install higher R versions (for this you don't need sudo rights) and run the "/path/to/your/local/R-3.5.1/bin/R" - eg - I do it indeed. 但是实际上也没有conda,您可以只在本地安装更高的R版本(为此,您不需要sudo权限)并运行“ /path/to/your/local/R-3.5.1/bin/R”-例如我确实做到了 Binaries or sources you get from here . 您从此处获得的二进制文件或资源。 However, in this case you often have to install packages as admin. 但是,在这种情况下,您通常必须以管理员身份安装软件包。

Using the .libPath() function, you can get full control over which libraries - which are located in folders - should be accessed/used or not. 使用.libPath()函数,您可以完全控制应访问/不使用哪些库(位于文件夹中)。 See here . 这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM