我试图从源代码安装R包mirt
,但收到错误。我在PC和Mac上都收到错误。请注意,我的PC和Mac都设置为从源代码安装软件包,并且我已经成功地在两个系统上从源代码中安装了软件包。例如,我已经验证了我可以使用以下命令在我的PC和Mac上成功地从源代码安装包jsonlite
:install.packages("jsonlite", type = "source")
。我的电脑上安装了Rtools 4.0,Mac上安装了Xcode和R编译器工具。mirt
包的创建者Phil Chalmers建议我的编译器可能需要重新配置(因为看起来g++.exe不在R可以看到的路径中(。如何修复此问题,以便从源代码安装mirt
软件包?
以下是我在电脑上尝试从源代码安装时收到的错误:
> install.packages('mirt', type = 'source')
Installing package into ‘C:/R/Packages’
(as ‘lib’ is unspecified)
trying URL 'https://cran.r-project.org/src/contrib/mirt_1.32.1.tar.gz'
Content type 'application/x-gzip' length 811759 bytes (792 KB)
downloaded 792 KB
Welcome at Tue Jul 28 22:32:44 2020
* installing *source* package 'mirt' ...
** package 'mirt' successfully unpacked and MD5 sums checked
** using staged installation
** libs
*** arch - i386
"C:/rtools40/mingw32/bin/"g++ -std=gnu++11 -I"C:/R/R-40~1.2/include" -DNDEBUG -I'C:/R/Packages/Rcpp/include' -I'C:/R/Packages/RcppArmadillo/include' -fopenmp -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c Estep.cpp -o Estep.o
"C:/rtools40/mingw32/bin/"g++ -std=gnu++11 -I"C:/R/R-40~1.2/include" -DNDEBUG -I'C:/R/Packages/Rcpp/include' -I'C:/R/Packages/RcppArmadillo/include' -fopenmp -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c Misc.cpp -o Misc.o
"C:/rtools40/mingw32/bin/"g++ -std=gnu++11 -I"C:/R/R-40~1.2/include" -DNDEBUG -I'C:/R/Packages/Rcpp/include' -I'C:/R/Packages/RcppArmadillo/include' -fopenmp -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c dpars.cpp -o dpars.o
"C:/rtools40/mingw32/bin/"g++ -std=gnu++11 -I"C:/R/R-40~1.2/include" -DNDEBUG -I'C:/R/Packages/Rcpp/include' -I'C:/R/Packages/RcppArmadillo/include' -fopenmp -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c ggum_derivs.cpp -o ggum_derivs.o
"C:/rtools40/mingw32/bin/"g++ -std=gnu++11 -I"C:/R/R-40~1.2/include" -DNDEBUG -I'C:/R/Packages/Rcpp/include' -I'C:/R/Packages/RcppArmadillo/include' -fopenmp -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c traceLinePts.cpp -o traceLinePts.o
C:/rtools40/mingw32/bin/g++ -std=gnu++11 -shared -s -static-libgcc -o mirt.dll tmp.def Estep.o Misc.o dpars.o ggum_derivs.o traceLinePts.o Welcome at Tue Jul 28 22:33:21 2020 Goodbye at Tue Jul 28 22:33:21 2020 -LC:/R/R-40~1.2/bin/i386 -lRlapack -LC:/R/R-40~1.2/bin/i386 -lRblas -lgfortran -lm -lquadmath -fopenmp -LC:/R/R-40~1.2/bin/i386 -lR
g++.exe: error: Welcome: No such file or directory
g++.exe: error: at: No such file or directory
g++.exe: error: Tue: No such file or directory
g++.exe: error: Jul: No such file or directory
g++.exe: error: 28: No such file or directory
g++.exe: error: 22:33:21: Invalid argument
g++.exe: error: 2020: No such file or directory
g++.exe: error: Goodbye: No such file or directory
g++.exe: error: at: No such file or directory
g++.exe: error: Tue: No such file or directory
g++.exe: error: Jul: No such file or directory
g++.exe: error: 28: No such file or directory
g++.exe: error: 22:33:21: Invalid argument
g++.exe: error: 2020: No such file or directory
no DLL was created
ERROR: compilation failed for package 'mirt'
* removing 'C:/R/Packages/mirt'
* restoring previous 'C:/R/Packages/mirt'
Warning in install.packages :
installation of package ‘mirt’ had non-zero exit status
The downloaded source packages are in
‘C:UsersIsaacAppDataLocalTempRtmpwfAN3Mdownloaded_packages’
会话信息:
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.0.2 tools_4.0.2
验证是否安装了Rtools 4.0:
> Sys.which("make")
make
"C:\rtools40\usr\bin\make.exe"
然而,R似乎不知道g++.exe
在哪里:
> system("g++ -v")
[1] 127
我最终能够弄清楚这一点。出现此问题是因为我的Rprofile.site
文件将文本打印到控制台:
.First <- function(){
cat("nWelcome at", date(), "n")
}
.Last <- function(){
cat("nGoodbye at ", date(), "n")
}
问题在于,如这里所指出的;这台机器上的.Rprofile
输出的cat
似乎正在插入g++
命令中。删除cat
调用后,库安装时不会出现错误">
在注释掉RProfile.site
文件中的cat
调用之后,我能够成功地从源代码安装包。