I am working on a package that supports interaction with an alternatively shaped library structure which supports installing multiple versions of a package in parallel (RVClibrary, soon on CRAN). Recently, I met some strange behaviour and I hope someone can explain.
When installing a package, it can sometimes have a source version which is later than the binary version. The source (uncompiled C code) is in that case not yet compiled (by ...?) but contains a later version than the already compiled binary version. The following is shown in my case:
There is a binary version available but the source version is later:
binary source needs_compilation
rlang 0.2.0 0.3.4 TRUE
A choice is given to the user whether A or B should be relatively installed or compiled. In other words, if you want version 0.2.0 or 0.3.4 (for which you need Rtools).
This choice will not be given when the install.packages.compile.from.source
option is set.
> options(install.packages.compile.from.source = "always")
> install.packages('rlang', lib = "C:\\test", quiet = TRUE, repos = "http://cran.us.r-project.org")
There is a binary version available but the source version is later:
binary source needs_compilation
rlang 0.2.0 0.3.4 TRUE
installing the source package ‘rlang’
The source is installed.
But when I create a simple script (I name it install_test.R
):
packageName <- commandArgs(trailingOnly = TRUE)[1]
cat(packageName, '\n')
options(install.packages.compile.from.source = "always")
install.packages(packageName, lib = "C:\\test", quiet = TRUE, repos = "http://cran.us.r-project.org")
The following behaves the same with system in R and directly in CMD.
(Make sure you have the path to Rscript.exe
in your environment variable PATH)
> system("Rscript.exe C:\\test\\install_test.R rlang")
rlang
There is a binary version available but the source version is later:
binary source needs_compilation
rlang 0.2.0 0.3.4 TRUE
Binaries will be installed
package 'rlang' successfully unpacked and MD5 sums checked
The Binaries are installed!
I need to be able to always install the Source version so I do not run into dependency issues. ggplot2 for example depends on >= 0.2.1
already...
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
year 2016
month 06
day 21
svn rev 70800
language R
version.string R version 3.3.1 (2016-06-21)
nickname Bug in Your Hair
(my edit here is removed to keep it clean. See my answer (or history) to read more)
答案 0 :(得分:0)
我尝试了不同的环境变量配置,以查看是否可以通过运行install.packages
的Rscript.exe 实例从源安装/编译。
(从Rstudio控制台工作时,它的工作方式有所不同(限制较少)。似乎它可以识别注册表项。它完全不需要指定环境变量就可以工作。)
MAKE
变量(Sys.setenv(MAKE = 'C:\\Rtools\\bin\\make.exe')
)(部分成功)PATH
变量(附加到开头)
C:\\Rtools\\bin;C:\\Rtools\\mingw_32;C:\\Rtools\\mingw_64
)(SUCCEEDS)C:\\Rtools\\bin
(SUCCEEDS)C:\\Rtools\\bin
(至PATH变量的末尾)(SUCCEEDS)C:\\Rtools\\mingw_32
(失败)C:\\Rtools\\mingw_64
(失败)PATH
而不设置MAKE
变量。在设置以下属性的情况下:options(install.packages.compile.from.source = "always")
解决方案1:
install.packages
函数通过查找'MAKE'环境变量nzchar(Sys.which(Sys.getenv("MAKE", "make")))
'检查'是否应尝试从源代码进行构建。不幸的是,如果仅指定MAKE环境变量(您必须提供完整的路径才能使它(Sys.which
)正常工作,它仍将找不到似乎是必需的所有必需的源构建工具(Rtools / bin)。必要并且崩溃,没有任何澄清:
> Sys.setenv(MAKE = 'C:\\Rtools\\bin\\make.exe')
> system("Rscript.exe C:\\R_projecten\\test\\install_test.R rlang")
There is a binary version available but the source version is later:
binary source needs_compilation
rlang 0.2.0 0.3.4 TRUE
installing the *source* package 'rlang'
Warning messages:
1: running command '"C:/PROGRA~1/R/R-33~1.1/bin/x64/R" CMD INSTALL -l "C:\R_projecten\test\test4" C:\Users\SB947~1.FRO\AppData\Local\Temp\RtmpwbEcl6/downloaded_packages/rlang_0.3.4.tar.gz' had status 1
2: In install.packages(packageName, lib = "C:\\R_projecten\\test\\test4", :
installation of package 'rlang' had non-zero exit status
因此,解决方案1是不够的,甚至可以用解决方案3代替:
PATH : C:\Program Files\R\R-3.3.1\bin\x64; .... ;C:\Rtools\bin;
MAKE :
There is a binary version available but the source version is later:
binary source needs_compilation
rlang 0.2.0 0.3.4 TRUE
installing the source package 'rlang'
如图所示,仅在PATH中提供C:/Rtools/bin
,并且没有MAKE变量就足够。
前面所述的检查将检查MAKE变量是否存在,并使用该值,否则它将寻找程序名make
(默认为Sys.getenv
)。仅指定PATH时,可以找到make(.exe)
文件,并且不需要MAKE env var。拥有已经指向Rtools / bin目录的额外好处,显然从该目录中需要更多文件。
我仍然想知道哪个文件...
注意:支票nzchar(Sys.which(Sys.getenv("MAKE", "make")))
不足以证明您的环境已准备好从源代码构建。