简体   繁体   中英

Why is R trying to compile strings written to stdout from .Rprofile when installing packages?

I've come across a strange error when trying to install the package wordcloud . I have an .Rprofile :

.First <- function(){
    if(R.version[["major"]] == "3"){
        if(R.version[["minor"]] == "4.2"){
            #.libPaths = .libPaths("~/Scratch/3.4.2-lib")
            .libPaths = .libPaths("/gpfs0/home/user/Scratch/dependencies/R-3.4.2_libs/")
        }else if(R.version[["minor"]] == "3.0"){
            .libPaths = .libPaths("~/.R/3.3.0-lib")

        }else if(R.version[["minor"]] == "2.3"){
            .libPaths = .libPaths("~/.R/3.2.3-lib")

        }else if(R.version[["minor"]] == "5.0"){
            .libPaths = .libPaths("~/.R/3.5.0-lib")

        }else{
            write("ERROR!! Something got messed up in ~/.Rprofile -> .First()",stderr())
            q(save = "no", status = 1, runLast = FALSE)
        }
    }else{
        write("ERROR!! No libraries built for R versions other than 3.X.X",stderr())
        q(save = "no", status = 1, runLast = FALSE)
    }
    write(sprintf("Looking for libraries in : %s",.libPaths()), stdout())
}

Using R-3.4.2 on CentOS 6.9, I try to install the package:

qmaster02: dependencies$ R

R version 3.4.2 (2017-09-28) -- "Short Summer"
.
. 
.

Looking for libraries in : /gpfs0/home/user/Scratch/dependencies/R-3.4.2_libs
Looking for libraries in : /gpfs0/export/opt/R/3.4.2/lib64/R/library
> install.packages("wordcloud")
Installing package into ‘/gpfs0/home/user/Scratch/dependencies/R-3.4.2_libs’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
also installing the dependencies ‘RColorBrewer’, ‘Rcpp’

trying URL 'https://cran.mtu.edu/src/contrib/RColorBrewer_1.1-2.tar.gz'
Content type 'application/x-gzip' length 11532 bytes (11 KB)
==================================================
downloaded 11 KB

trying URL 'https://cran.mtu.edu/src/contrib/Rcpp_1.0.0.tar.gz'
Content type 'application/x-gzip' length 3635277 bytes (3.5 MB)
==================================================
downloaded 3.5 MB

trying URL 'https://cran.mtu.edu/src/contrib/wordcloud_2.6.tar.gz'
Content type 'application/x-gzip' length 42454 bytes (41 KB)
==================================================
downloaded 41 KB

Looking for libraries in : /gpfs0/home/user/Scratch/dependencies/R-3.4.2_libs
Looking for libraries in : /gpfs0/export/opt/R/3.4.2/lib64/R/library
* installing *source* package ‘RColorBrewer’ ...
** package ‘RColorBrewer’ successfully unpacked and MD5 sums checked
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Looking for libraries in : /gpfs0/home/user/Scratch/dependencies/R-3.4.2_libs
Looking for libraries in : /gpfs0/export/opt/R/3.4.2/lib64/R/library
* DONE (RColorBrewer)
Looking for libraries in : /gpfs0/home/user/Scratch/dependencies/R-3.4.2_libs
Looking for libraries in : /gpfs0/export/opt/R/3.4.2/lib64/R/library
* installing *source* package ‘Rcpp’ ...
** package ‘Rcpp’ successfully unpacked and MD5 sums checked
** libs
g++  -I/opt/R/3.4.2/lib64/R/include -DNDEBUG -I../inst/include/  -I/opt/zlib/1.2.11/include -I/opt/bzip2/1.0.6/include/ -I/opt/xz/5.2.3/include -I/opt/pcre/8.38/include -I/opt/curl/7.47.1/include   -fpic  -g -O2  -c Date.cpp -o Date.o
g++  -I/opt/R/3.4.2/lib64/R/include -DNDEBUG -I../inst/include/  -I/opt/zlib/1.2.11/include -I/opt/bzip2/1.0.6/include/ -I/opt/xz/5.2.3/include -I/opt/pcre/8.38/include -I/opt/curl/7.47.1/include   -fpic  -g -O2  -c Module.cpp -o Module.o
g++  -I/opt/R/3.4.2/lib64/R/include -DNDEBUG -I../inst/include/  -I/opt/zlib/1.2.11/include -I/opt/bzip2/1.0.6/include/ -I/opt/xz/5.2.3/include -I/opt/pcre/8.38/include -I/opt/curl/7.47.1/include   -fpic  -g -O2  -c Rcpp_init.cpp -o Rcpp_init.o
g++  -I/opt/R/3.4.2/lib64/R/include -DNDEBUG -I../inst/include/  -I/opt/zlib/1.2.11/include -I/opt/bzip2/1.0.6/include/ -I/opt/xz/5.2.3/include -I/opt/pcre/8.38/include -I/opt/curl/7.47.1/include   -fpic  -g -O2  -c api.cpp -o api.o
g++  -I/opt/R/3.4.2/lib64/R/include -DNDEBUG -I../inst/include/  -I/opt/zlib/1.2.11/include -I/opt/bzip2/1.0.6/include/ -I/opt/xz/5.2.3/include -I/opt/pcre/8.38/include -I/opt/curl/7.47.1/include   -fpic  -g -O2  -c attributes.cpp -o attributes.o
g++  -I/opt/R/3.4.2/lib64/R/include -DNDEBUG -I../inst/include/  -I/opt/zlib/1.2.11/include -I/opt/bzip2/1.0.6/include/ -I/opt/xz/5.2.3/include -I/opt/pcre/8.38/include -I/opt/curl/7.47.1/include   -fpic  -g -O2  -c barrier.cpp -o barrier.o
g++ -shared -L/opt/R/3.4.2/lib64/R/lib -L/opt/zlib/1.2.11/ -L/opt/bzip2/1.0.6/lib/ -L/opt/xz/5.2.3/lib -L/opt/pcre/8.38/lib -L/opt/curl/7.47.1/lib/ -o Rcpp.so Date.o Module.o Rcpp_init.o api.o attributes.o barrier.o -L/opt/R/3.4.2/lib64/R/lib -lR
installing to /gpfs0/home/user/Scratch/dependencies/R-3.4.2_libs/Rcpp/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
Looking for libraries in : /gpfs0/home/user/Scratch/dependencies/R-3.4.2_libs
Looking for libraries in : /gpfs0/export/opt/R/3.4.2/lib64/R/library
* DONE (Rcpp)
Looking for libraries in : /gpfs0/home/user/Scratch/dependencies/R-3.4.2_libs
Looking for libraries in : /gpfs0/export/opt/R/3.4.2/lib64/R/library
* installing *source* package ‘wordcloud’ ...
** package ‘wordcloud’ successfully unpacked and MD5 sums checked
** libs
g++  -I/opt/R/3.4.2/lib64/R/include -DNDEBUG  -I"/gpfs0/home/user/Scratch/dependencies/R-3.4.2_libs/Rcpp/include" -I/opt/zlib/1.2.11/include -I/opt/bzip2/1.0.6/include/ -I/opt/xz/5.2.3/include -I/opt/pcre/8.38/include -I/opt/curl/7.47.1/include   -fpic  -g -O2  -c RcppExports.cpp -o RcppExports.o
g++  -I/opt/R/3.4.2/lib64/R/include -DNDEBUG  -I"/gpfs0/home/user/Scratch/dependencies/R-3.4.2_libs/Rcpp/include" -I/opt/zlib/1.2.11/include -I/opt/bzip2/1.0.6/include/ -I/opt/xz/5.2.3/include -I/opt/pcre/8.38/include -I/opt/curl/7.47.1/include   -fpic  -g -O2  -c layout.cpp -o layout.o
g++ -shared -L/opt/R/3.4.2/lib64/R/lib -L/opt/zlib/1.2.11/ -L/opt/bzip2/1.0.6/lib/ -L/opt/xz/5.2.3/lib -L/opt/pcre/8.38/lib -L/opt/curl/7.47.1/lib/ -o wordcloud.so RcppExports.o layout.o Looking for libraries in : /gpfs0/home/user/Scratch/dependencies/R-3.4.2_libs Looking for libraries in : /gpfs0/export/opt/R/3.4.2/lib64/R/library -L/opt/R/3.4.2/lib64/R/lib -lR
g++: error: Looking: No such file or directory
g++: error: for: No such file or directory
g++: error: libraries: No such file or directory
g++: error: in: No such file or directory
g++: error: :: No such file or directory
g++: error: Looking: No such file or directory
g++: error: for: No such file or directory
g++: error: libraries: No such file or directory
g++: error: in: No such file or directory
g++: error: :: No such file or directory
make: *** [wordcloud.so] Error 1
ERROR: compilation failed for package ‘wordcloud’
* removing ‘/gpfs0/home/user/Scratch/dependencies/R-3.4.2_libs/wordcloud’
Warning in install.packages("wordcloud") :
  installation of package ‘wordcloud’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/RtmpACcxZ9/downloaded_packages’

With the last few compilation lines, you can see that R has decided to try and linking the string Looking for libraries in ... as separate object files. This is very perplexing.

The way to prevent this from happening is to comment out the write line in .Rprofile , but this is annoying to do whenever you need to install packages.

QUESTION : Why is R doing this and why did it only happen on the wordcloud package?

It is because of this (very old!!) line in Makevars :

PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"`

When it was written, this was needed to get the link instructions for Rcpp from Rcpp. But since 2013 this is no longer needed, and the line can be deleted. Feel free to file a bug report with Ian.

That said, you system is brittle too. You should not print from the initialization files, or at least not if you detect non-interactive mode. Use something like

if (interactive()) { ... }

to protect the output generation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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