Reputation: 93
My colleagues and I are working on a book with Bookdown in RStudio. Since I create a lot of graphics with ggplot and therefore I have many dependencies to other packages (ggplot, ggforce, gganimate, ...), I added renv in the course of the book to take care of package management. After a clean installation of my Windows I do now have problems to set up the project again, because there were updates from R to version 3.6.3 and used packages.
Initial state of the project with renv was R with version 3.6.2, which I reinstalled. After opening the project I run renv::restore()
to restore the environment with all packages. Currently only the package nloptr (version 1.2.1) has a bug, because it has to build the package from source.
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
To work around this error I install the package manually via:
packageurl <- "https://cran.r-project.org/bin/windows/contrib/3.7/nloptr_1.2.1.zip"
install.packages(packageurl, repos=NULL, type="binary")
After that all packages can be installed but now, many of them show the warning package 'X' was built under R version 3.6.3
.
What's the point of renv if it can't restore the original state, because all packages have been changed by an update of R? How can I manage an R project properly ?
Upvotes: 6
Views: 1599
Reputation: 21285
The underlying issue here is that nloptr
was recently updated to version 1.2.2.1, and so binaries for 1.2.1 are no longer available on CRAN.
The simplest solution, then, is to upgrade to the latest version of nloptr
, so that you can access the newer binary. Alternatively, you can use a checkpointed MRAN repository locked to that particular point in time so that binaries available on that day can be served.
If you want to be able to install nloptr
from sources, you might consider upgrading to the development version of renv
. You can use renv::equip()
to download the requisite libraries needed to compile nloptr
(and some other R packages) from sources. For example:
> 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'
You can install the development version of renv
with:
renv::upgrade(version = "master")
Make sure to restart the R session after updating renv
.
Upvotes: 4