【问题标题】:How to maintain R (renv) project如何维护 R (renv) 项目
【发布时间】:2020-03-11 15:38:13
【问题描述】:

我和我的同事正在使用 RStudio 中的 Bookdown 编写一本书。由于我使用 ggplot 创建了很多图形,因此我对其他包(ggplot、ggforce、gganimate...)有很多依赖关系,因此我在本书的过程中添加了 renv 来处理包管理。全新安装 Windows 后,我现在再次设置项目时遇到问题,因为从 R 到版本 3.6.3 的更新和使用的包。

带有 renv 的项目的初始状态是 R 版本 3.6.2,我重新安装了它。打开项目后,我运行renv::restore() 以使用所有包恢复环境。目前只有包 nloptr(版本 1.2.1)有错误,因为它必须从源代码构建包。

Installing minqa [1.2.4] ...
    OK (linked cache)
Installing nloptr [1.2.1] ...
    FAILED
Error installing package 'nloptr':
==================================

* installing *source* package 'nloptr' ...
** package 'nloptr' successfully unpacked and MD5 sums checked
** using staged installation

   **********************************************
   WARNING: this package has a configure script
         It probably needs manual configuration
   **********************************************


** libs
C:/Rtools/mingw_64/bin/g++ -std=gnu++11  -I"C:/PROGRA~1/R/R-36~1.2/include" -DNDEBUG          -O2 -Wall  -mtune=generic -c dummy.cpp -o dummy.o
C:/Rtools/mingw_64/bin/gcc  -I"C:/PROGRA~1/R/R-36~1.2/include" -DNDEBUG       -I"/x64/include"   -O2 -Wall  -std=gnu99 -mtune=generic -c init_nloptr.c -o init_nloptr.o
init_nloptr.c:35:19: fatal error: nlopt.h: No such file or directory
 #include "nlopt.h"
                   ^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-36~1.2/etc/x64/Makeconf:208: init_nloptr.o] Error 1
ERROR: compilation failed for package 'nloptr'
* removing 'C:/Users/Ralph/DOCUME~1/ML2/ml2-buch/renv/staging/1/nloptr'
Fehler: install of package 'nloptr' failed

要解决此错误,我通过以下方式手动安装包:

packageurl <- "https://cran.r-project.org/bin/windows/contrib/3.7/nloptr_1.2.1.zip"
install.packages(packageurl, repos=NULL, type="binary")

之后可以安装所有软件包,但现在,其中许多显示警告package 'X' was built under R version 3.6.3

renv 如果它不能恢复原始状态,因为所有的包都被 R 的更新改变了,那它有什么意义呢?如何正确管理 R 项目?

【问题讨论】:

  • 我很同情这种困境,拉尔夫。这可能renv 的错误(我不肯定)。但为了清楚起见,您的问题是 nloptr 不可编译性,是 renv 没有选择二进制包,还是您不喜欢 "built under" 警告?跨度>
  • @r2evans 感谢您的同情^^。两者更大的问题是nloptr(可能只有Windows)不能在locked 版本中自动安装。所以你必须从头开始设置你的环境:要么你必须自己构建所需的包,要么必须安装一个新版本,这可能会有一个新的行为。目前只有1个包,半年后10个包都做不出来了,一个新同事想继续写这本书怎么办?

标签: r package-management renv


【解决方案1】:

这里的根本问题是 nloptr 最近更新到版本 1.2.2.1,因此 CRAN 上不再提供 1.2.1 的二进制文件。

那么,最简​​单的解决方案是升级到最新版本的nloptr,以便您可以访问更新的二进制文件。或者,您可以使用锁定到该特定时间点的检查点 MRAN 存储库,以便可以提供当天可用的二进制文件。

如果您希望能够从源安装nloptr,您可以考虑升级到renv 的开发版本。您可以使用renv::equip() 从源代码中下载编译nloptr(和其他一些R 包)所需的库。例如:

> renv::equip()
The following external software tools will be installed:

    curl-7.68.0-win32-mingw.zip
    glpk32.zip
    glpk64.zip
    local323.zip
    nlopt-2.4.2.zip
    spatial324.zip

Tools will be installed into '~/AppData/Local/renv/extsoft'.

Do you want to proceed? [y/N]: y
Retrieving 'https://s3.amazonaws.com/rstudio-buildtools/extsoft/curl-7.68.0-win32-mingw.zip' ...
    OK [downloaded 2.9 Mb in 1.5 secs]
Retrieving 'https://s3.amazonaws.com/rstudio-buildtools/extsoft/glpk32.zip' ...
    OK [downloaded 457.7 Kb in 1 secs]
Retrieving 'https://s3.amazonaws.com/rstudio-buildtools/extsoft/glpk64.zip' ...
    OK [downloaded 481.6 Kb in 1 secs]
Retrieving 'https://s3.amazonaws.com/rstudio-buildtools/extsoft/local323.zip' ...
    OK [downloaded 9.6 Mb in 2.3 secs]
Retrieving 'https://s3.amazonaws.com/rstudio-buildtools/extsoft/nlopt-2.4.2.zip' ...
    OK [downloaded 752.6 Kb in 1.2 secs]
Retrieving 'https://s3.amazonaws.com/rstudio-buildtools/extsoft/spatial324.zip' ...
    OK [downloaded 20.9 Mb in 2.6 secs]
* External software successfully updated.
The following entries will be added to ~/.R/Makevars:

    LOCAL_SOFT = C:/Users/kevin/AppData/Local/renv/extsoft
    LIB_XML = C:/Users/kevin/AppData/Local/renv/extsoft
    LOCAL_CPPFLAGS = -I"$(LOCAL_SOFT)/include"
    LOCAL_LIBS = -L"$(LOCAL_SOFT)/lib$(R_ARCH)" -L"$(LOCAL_SOFT)/lib"

These tools will be used when compiling R packages from source.

Do you want to proceed? [y/N]: y
* '~/.R/Makevars' has been updated.

> install.packages("nloptr", type = "source")
* installing *source* package 'nloptr' ...
** package 'nloptr' successfully unpacked and MD5 sums checked
** using staged installation

   **********************************************
   WARNING: this package has a configure script
         It probably needs manual configuration
   **********************************************


** libs

*** arch - i386
c:/Rtools/mingw_32/bin/g++ -std=gnu++11  -I"C:/R/R-36~1.2RC/include" -DNDEBUG     -I"C:/Users/kevin/AppData/Local/renv/extsoft/include"     -g -O2 -Wall -pedantic -c dummy.cpp -o dummy.o
c:/Rtools/mingw_32/bin/gcc  -I"C:/R/R-36~1.2RC/include" -DNDEBUG     -I"C:/Users/kevin/AppData/Local/renv/extsoft/include"  -I"/i386/include"   -g -O3 -Wall -pedantic -c init_nloptr.c -o init_nloptr.o
c:/Rtools/mingw_32/bin/g++ -std=gnu++11 -shared -s -static-libgcc -o nloptr.dll tmp.def dummy.o init_nloptr.o nloptr.o -L/i386/lib -lnlopt_cxx -LC:/Users/kevin/AppData/Local/renv/extsoft/lib/i386 -LC:/Users/kevin/AppData/Local/renv/extsoft/lib -LC:/R/R-36~1.2RC/bin/i386 -lR
installing to C:/Users/kevin/R/win-library/3.6/00LOCK-nloptr/00new/nloptr/libs/i386

*** arch - x64
c:/Rtools/mingw_64/bin/g++ -std=gnu++11  -I"C:/R/R-36~1.2RC/include" -DNDEBUG     -I"C:/Users/kevin/AppData/Local/renv/extsoft/include"     -g -O2 -Wall -pedantic -c dummy.cpp -o dummy.o
c:/Rtools/mingw_64/bin/gcc  -I"C:/R/R-36~1.2RC/include" -DNDEBUG     -I"C:/Users/kevin/AppData/Local/renv/extsoft/include"  -I"/x64/include"   -g -O3 -Wall -pedantic -c init_nloptr.c -o init_nloptr.o
c:/Rtools/mingw_64/bin/g++ -std=gnu++11 -shared -s -static-libgcc -o nloptr.dll tmp.def dummy.o init_nloptr.o nloptr.o -L/x64/lib -lnlopt_cxx -LC:/Users/kevin/AppData/Local/renv/extsoft/lib/x64 -LC:/Users/kevin/AppData/Local/renv/extsoft/lib -LC:/R/R-36~1.2RC/bin/x64 -lR
installing to C:/Users/kevin/R/win-library/3.6/00LOCK-nloptr/00new/nloptr/libs/x64
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
  converting help for package 'nloptr'
    finding HTML links ... done
    auglag                                  html  
    bobyqa                                  html  
    ccsaq                                   html  
    check.derivatives                       html  
    cobyla                                  html  
    crs2lm                                  html  
    direct                                  html  
    is.nloptr                               html  
    isres                                   html  
    lbfgs                                   html  
    mlsl                                    html  
    mma                                     html  
    neldermead                              html  
    newuoa                                  html  
    nl.grad                                 html  
    nl.opts                                 html  
    nloptr-package                          html  
    nloptr                                  html  
    nloptr.get.default.options              html  
    nloptr.print.options                    html  
    print.nloptr                            html  
    sbplx                                   html  
    slsqp                                   html  
    stogo                                   html  
    tnewton                                 html  
    varmetric                               html  
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
*** arch - i386
*** arch - x64
** testing if installed package can be loaded from final location
*** arch - i386
*** arch - x64
** testing if installed package keeps a record of temporary installation path
* DONE (nloptr)

The downloaded source packages are in
    'C:\Users\kevin\AppData\Local\Temp\RtmpW4Mr1M\downloaded_packages'

你可以安装renv的开发版:

renv::upgrade(version = "master")

确保在更新renv 后重新启动 R 会话。

【讨论】:

    猜你喜欢
    • 2022-09-22
    • 2020-12-21
    • 2011-02-04
    • 2011-03-14
    • 2013-01-20
    • 2019-08-29
    • 2023-03-30
    • 1970-01-01
    • 2023-03-22
    相关资源
    最近更新 更多