R not recognizing my alternative GCC compiler after config updates? - r

I followed these instructions to get R to use an alternative GCC compiler I have installed on my MacOS.
Building R Packages using Alternate GCC
As basic internet research will tell you (as it told me), the default compiler on the MacOS is clang / clang++, which doesn't work for my specific needs. I installed gcc-8.1 and dependencies in order to enable OpenMP on my machine. OpenMP works when I run gcc-8.1 with a standalone tmp.c file with pragma omp commands in it.
However, when I go back to R to try to run the same code using Rcpp R package, I run into some problems.
The below is what is in my Makevars file located at ~/.R/Makevars on my machine.
PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) $(SHLIB_OPENMP_CFLAGS)
PKG_CFLAGS = $(SHLIB_OPENMP_CFLAGS)
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
CC=gcc-8.1
CXX=g++-8.1
CXX98=g++-8.1
CXX11=g++-8.1
CXX14=g++-8.1
CXX17=g++-8.1
This now correctly activates my alternative complier in lieu of clang++. I can install my package with OpenMP functionality by using a Terminal and using the R commands below.
cd /folder/where/package/is
R CMD build packageName
R CMD build packageName_1.0.tar.gz
However, I cannot install the package using devtools and roxygen2, which I would prefer. Specifically, the devtools function has_devel() fails.
has_devel()
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet CMD SHLIB foo.c
gcc-8.1 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/include -fopenmp -fPIC -Wall -g -O2 -c foo.c -o foo.o
/bin/sh: gcc-8.1: command not found
make: *** [foo.o] Error 127
Error: Command failed (1)
Here is the code I use when trying to install updates using devtools / roxygen2.
require(Rcpp)
require(devtools)
require(roxygen2)
setwd("/folder/where/package/is")
compileAttributes(pkgdir = "/folder/where/package/is")
install("packageName/")
I suspect the pop up window I get from RStudio is directly related to has_devel() function failing to be TRUE. If I revert back to using the default compiler, clang++ (by deleting my Makevars at ~/.R/Makevars), has_devel() returns TRUE and RStudio doesn't ask if I want to install developer command line tools. How can I get around this hiccup with installing a package I am developing using devtools instead of installing from source each time?

Related

RcppExports.o Error 127 when trying to install Monocle3 [duplicate]

I'm trying to use packages that require Rcpp in R on my M1 Mac, which I was never able to get up and running after purchasing this computer. I updated it to Monterey in the hope that this would fix some installation issues but it hasn't. I tried running the Rcpp check from this page but I get the following error:
> Rcpp::sourceCpp("~/github/helloworld.cpp")
ld: warning: directory not found for option '-L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0'
ld: warning: directory not found for option '-L/opt/R/arm64/gfortran/lib'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sourceCpp_4.so] Error 1
clang++ -arch arm64 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I../inst/include -I"/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/RcppArmadillo/include" -I"/Users/afredston/github" -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c helloworld.cpp -o helloworld.o
clang++ -arch arm64 -std=gnu++14 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o sourceCpp_4.so helloworld.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0 -L/opt/R/arm64/gfortran/lib -lgfortran -lemutls_w -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
Error in Rcpp::sourceCpp("~/github/helloworld.cpp") :
Error 1 occurred building shared library.
I get that it can't "find" gfortran. I installed this release of gfortran for Monterey. When I type which gfortran into Terminal, it returns /opt/homebrew/bin/gfortran. (Maybe this version of gfortran requires Xcode tools that are too new—it says something about 13.2 and when I run clang --version it says 13.0—but I don't see another release of gfortran for Monterey?)
I also appended /opt/homebrew/bin: to PATH in R so it looks like this now:
> Sys.getenv("PATH")
[1] "/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin:/Applications/RStudio.app/Contents/MacOS/postback"
Other things I checked:
Xcode command line tools is installed (which clang returns /usr/bin/clang).
Files ~/.R/Makevars and ~/.Renviron don't exist.
Here's my session info:
R version 4.1.1 (2021-08-10)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.1
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.1.1 tools_4.1.1 RcppArmadillo_0.10.7.5.0
[4] Rcpp_1.0.7
Background
Currently (2023-02-20), CRAN builds R 4.2 binaries for Apple silicon using Apple clang from Command Line Tools for Xcode 13.1 and using an experimental fork of GNU Fortran 12.
If you obtain R from CRAN (i.e., here), then you need to replicate CRAN's compiler setup on your system before building R packages that contain C/C++/Fortran code from their sources (and before using Rcpp, etc.). This requirement ensures that your package builds are compatible with R itself.
A further complication is the fact that Apple clang doesn't support OpenMP, so you need to do even more work to compile programs that make use of multithreading. You could circumvent the issue by building R itself and all R packages from sources with LLVM clang, which does support OpenMP, but that approach is onerous and "for experts only".
There is another approach that has been tested by a few people, including Simon Urbanek, the maintainer of R for macOS. It is experimental and also "for experts only", but it works on my machine and is much simpler than learning to build R yourself.
Instructions for obtaining a working toolchain
Warning: These come with no warranty and could break at any time. Some level of familiarity with C/C++/Fortran program compilation, Makefile syntax, and Unix shells is assumed. Everyone is encouraged to consult official documentation, which is more likely to be maintained than answers on SO. As usual, sudo at your own risk.
I will try to address compilers and OpenMP support at the same time. I am going to assume that you are starting from nothing. Feel free to skip steps you've already taken, though you might find a fresh start helpful.
I've tested these instructions on a machine running Big Sur, and at least one person has tested them on a machine running Monterey. I would be glad to hear from others.
Download an R 4.2 binary from CRAN here and install. Be sure to select the binary built for Apple silicon.
Run
$ sudo xcode-select --install
in Terminal to install the latest release version of Apple's Command Line Tools for Xcode, which includes Apple clang. You can obtain earlier versions from your browser here. However, the version that you install should not be older than the one that CRAN used to build your R binary.
Download the gfortran binary recommended here and install by unpacking to root:
$ curl -LO https://mac.r-project.org/tools/gfortran-12.0.1-20220312-is-darwin20-arm64.tar.xz
$ sudo tar xvf gfortran-12.0.1-20220312-is-darwin20-arm64.tar.xz -C /
$ sudo ln -sfn $(xcrun --show-sdk-path) /opt/R/arm64/gfortran/SDK
The last command updates a symlink inside of the gfortran installation so that it points to the SDK inside of your Command Line Tools installation.
Download an OpenMP runtime suitable for your Apple clang version here and install by unpacking to root. You can query your Apple clang version with clang --version. For example, I have version 1300.0.29.3, so I did:
$ curl -LO https://mac.r-project.org/openmp/openmp-12.0.1-darwin20-Release.tar.gz
$ sudo tar xvf openmp-12.0.1-darwin20-Release.tar.gz -C /
After unpacking, you should find these files on your system:
/usr/local/lib/libomp.dylib
/usr/local/include/ompt.h
/usr/local/include/omp.h
/usr/local/include/omp-tools.h
Add the following lines to $(HOME)/.R/Makevars, creating the file if necessary.
CPPFLAGS += -I/usr/local/include -Xclang -fopenmp
LDFLAGS += -L/usr/local/lib -lomp
Run R and test that you can compile a program with OpenMP support. For example:
if (!requireNamespace("RcppArmadillo", quietly = TRUE))
install.packages("RcppArmadillo")
Rcpp::sourceCpp(code = '
#include <RcppArmadillo.h>
#ifdef _OPENMP
# include <omp.h>
#endif
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
void omp_test()
{
#ifdef _OPENMP
Rprintf("OpenMP threads available: %d\\n", omp_get_max_threads());
#else
Rprintf("OpenMP not supported\\n");
#endif
}
')
omp_test()
OpenMP threads available: 8
If the C++ code fails to compile, or if it compiles without error but you get linker warnings or you find that OpenMP is not supported, then one of us has probably made a mistake. Please report any issues.
References
Everything is a bit scattered:
R Installation and Administration manual [link]
R for macOS Developers page [link]
I resolved this issue by adding a path to the homebrew installation of gfortran to my ~/.R/Makevars following these instructions: https://pat-s.me/transitioning-from-x86-to-arm64-on-macos-experiences-of-an-r-user/#gfortran
I just avoided the issue until MacOS had things working more smoothly. so I either Windows Developer Virtual Machine (VM) or run my code development in another environment. I'm not too impressed with the updated and "faster" chipset, but that it doesn't work with much. Slow to implement and work-a-rounds often are a must.
Tested the following process for making multithread data.table work in a M2 MacBook Pro (macOS Monterey)
Steps are mostly the same with this answer by the user inferator.
Download and install R from CRAN
Download and install RStudio with developer tools
Run the following commands in terminal to install OpenMP
curl -O https://mac.r-project.org/openmp/openmp-12.0.1-darwin20-Release.tar.gz
sudo tar fvxz openmp-12.0.1-darwin20-Release.tar.gz -C /
Add compiler flags to connect clan w/ OpenMP. In terminal, write the following:
cd ~
mkdir .R
nano .R/Makevars
Inside the opened Makevars file paste the following lines. Once finished, hit command+O and then Enter to save. Do a command+X to close the editor.
CPPFLAGS += -Xclang -fopenmp
LDFLAGS += -lomp
Download and run the installer for gfortran by downloading gfortran-ARM-12.1-Monterey.dmg from the respective GitHub repo
This concludes the steps regarding enabling OpenMP and (hopefully) Rcpp in R under a M2 chip system.
Now, for testing that everything works with data.table I did the following
Open RStudio and run
install.packages("data.table", type = "source")
If everything is done correctly, the package should compile without any errors and return the following when running getDTthreads(verbose = TRUE):
OpenMP version (_OPENMP) 201811
omp_get_num_procs() 8
R_DATATABLE_NUM_PROCS_PERCENT unset (default 50)
R_DATATABLE_NUM_THREADS unset
R_DATATABLE_THROTTLE unset (default 1024)
omp_get_thread_limit() 2147483647
omp_get_max_threads() 8
OMP_THREAD_LIMIT unset
OMP_NUM_THREADS unset
RestoreAfterFork true
data.table is using 4 threads with throttle==1024. See ?setDTthreads.
[1] 4

'RcppArmadillo.h' file not found when installing RcppArmadillo from source

RcppArmadillo 0.8.400.0.0 works just fine on my computer, both from sourceCpp and cxxfunction. Now I want to upgrade to 0.8.500.0, which requires compilation from source. Then I got the error
ccache /usr/local/clang6/bin/clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include -I/Applications/CPLEX_Studio128/cplex/include -I/Applications/CPLEX_Studio128/concert/include -DIL_STD -fPIC -Wall -g -O2 -c RcppArmadillo.cpp -o RcppArmadillo.o
RcppArmadillo.cpp:22:10: fatal error: 'RcppArmadillo.h' file not found
#include <RcppArmadillo.h>
^~~~~~~~~~~~~~~~~
1 error generated.
I got this error whether I ran install.packages("RcppArmadillo") in RStudio or in R console outside RStudio. My compiler is clang4, and I have no problem installing RcppParallel or compiling my own Rcpp code that uses RcppArmadillo and RcppParallel. R version: 3.5.0, MacOS High Sierra.
Edit: I looked at https://github.com/RcppCore/RcppArmadillo/issues/143, which is very relevant. I did install clang6 and gfortran 6.1, both downloaded from the CRAN website. I also changed the .R/Makevars file to reflect the changes to clang6. I have also installed ccache as suggested, to make compilation faster. Here's my Makevars:
F77 = /usr/local/gfortran/bin/gfortran
FC = $F77
FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
CC=ccache /usr/local/clang6/bin/clang
SHLIB_CXXLD=ccache /usr/local/clang6/bin/clang++
CXX= ccache /usr/local/clang6/bin/clang++ -Wall
CXX1X= ccache /usr/local/clang6/bin/clang++
CXX98= ccache /usr/local/clang6/bin/clang++
CXX11= ccache /usr/local/clang6/bin/clang++
CXX14= ccache /usr/local/clang6/bin/clang++
CXX17= ccache /usr/local/clang6/bin/clang++
LDFLAGS=-L/usr/local/clang6/lib
From the outputs in the R console when I was installing the package (added to the error message above), I can tell that clang6 was used for compilation. I also found the downloaded RcppArmadillo tarball, unpacked it, and ran ./configure from the command line. Nothing seemed wrong there; no config.log file was generated. This doesn't seem to be a configuration problem. Then I still got the exact same error when trying to install the package in R, after configuration, in libs. I also didn't get any message about -fopenmp. It seems that my problem is a bit different from that in the GitHub ticket.
R 3.5.x requires clang6 and adding clang6 to your system PATH variable.
Steps:
x Download and install the clang-6.0.0.pkg official package from CRAN.
x Delete your ~/.R/Makevars as it is likely set to use clang4. To do this, open Terminal and type:
sudo rm ~/.R/Makevars
x Then add to your ~/.bash_profile the following:
if [ -d "/usr/local/clang6/bin" ] ; then
export PATH="/usr/local/clang6/bin:$PATH"
fi
Note: If you are using a shell other than bash you will need to add the above into the appropriate file, e.g. for zsh add to ~/.zshrc, as this was not implemented in the official installer.
I should have a few cycles to finish writing a new unofficial Rtools installer a bit later. See: https://github.com/coatless/r-macos-rtools/issues/7
Note: Alternatively, you can remove the paths individual with
sudo vi ~/.R/Makevars
Pressing I to enter insert mode, deleting lines with clang4 in the path, and then pressing ESC + :wq to write changes to file.
Never mind, this problem went away with version 0.8.600. Later, this problem appeared again when I upgraded to RcppArmadillo 0.9.100.5.0. Somehow I only got this error when building from source; I downloaded the binary manually from the CRAN website, and used R CMD INSTALL to install the prebuilt version, and it worked; somehow R doesn't seem to know that there is a binary available for the newest version.
I did install clang6 and modified .R/Makevars to use clang6, but the same problem persisted; probably something else caused the problem.

Installing nloptr on Linux

I am trying to install the R package nloptr on a CentOS Linux machine that doesn't have internet connection as follows:
install.packages("/home/ravi/nloptr_1.0.4.tar.gz", repos = NULL, type="source")
This command in turn looks for the following file online
http://ab-initio.mit.edu/nlopt/nlopt-2.4.2.tar.gz
However, this fails since there is no internet connection to the machine.
I tried the suggestion from the following stackoverflow post:
trouble with Installing nloptr by locally on Ubuntu
I changed the URL in configure and configure.ac files as follows:
NLOPT_URL="file:///home//ravi//${NLOPT_TGZ}"
However, I get the following error when I try to install the package again:
> install.packages("/home/ravi/nloptr_1.0.4.tar.gz", repos = NULL, type="source")
* installing *source* package 'nloptr' ...
files 'configure', 'configure.ac' have the wrong MD5 checksums
ERROR: 'configure' exists but is not executable -- see the 'R Installation and Administration Manual'
* removing '/opt/vertica/R/library/nloptr'
Warning message:
In install.packages("/home/ravi/nloptr_1.0.4.tar.gz", :
installation of package '/home/ravi/nloptr_1.0.4.tar.gz' had non-zero exit status
Can someone guide me on how to install this R package locally?
Update 1
Based on the suggestion from Dirk on installing nlopt first, I followed the instructions given in the following page:
http://ab-initio.mit.edu/wiki/index.php/NLopt_Installation
I installed nlopt as follows :
./configure --enable-shared
make
make install
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib
When I tried to re-install nloptr in R, it doesn't look for the nlopt link anymore but throws the following error:
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/opt/vertica/R/library/nloptr/libs/nloptr.so':
/opt/vertica/R/library/nloptr/libs/nloptr.so: undefined symbol: nlopt_set_maxtime
Error: loading failed
Execution halted
ERROR: loading failed
* removing '/opt/vertica/R/library/nloptr'
Warning message:
In install.packages("/home/ravi/nloptr_1.0.4.tar.gz", :
installation of package '/home/ravi/nloptr_1.0.4.tar.gz' had non-zero exit status
Update 2
As suggested by Dirk, I looked into the ldconfig command and used the following reference:
http://codeyarns.com/2014/01/14/how-to-add-library-directory-to-ldconfig-cache/
I edited the /etc/ld.so.conf file, added the directory /usr/local/lib which contains the shared library and ran the ldconfig command. This added the relevant shared library as shown below:
libnlopt.so.0 (libc6,x86-64) => /usr/local/lib/libnlopt.so.0
libnlopt.so (libc6,x86-64) => /usr/local/lib/libnlopt.so
However, when I tried reinstalling the nloptr package, I still get the same shared object error.
Could someone guide me on the shared library error?
When you say [t]his command in turn looks for the following file online you only get half the story. Together with Jelmer, the maintainer of the actual nloptr package, I modified the package to do the following:
look for an install libnlopt library, and, if found, use it
if not found fall back to the old behaviour and download the library
So you could simply install nlopt via
sudo apt-get install libnlopt-dev
(or the equivalent sudo dpkg -i /media/.... pointing to the file from a
USB drive etc pp) and then reinstall the nloptr package. It will just work. On my machine:
edd#max:~$ install.r nloptr ## install.r is in littler
trying URL 'http://cran.rstudio.com/src/contrib/nloptr_1.0.4.tar.gz'
Content type 'application/x-gzip' length 353942 bytes (345 KB)
==================================================
downloaded 345 KB
* installing *source* package ‘nloptr’ ...
** package ‘nloptr’ successfully unpacked and MD5 sums checked
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking whether we are using the GNU C++ compiler... (cached) yes
checking whether g++ accepts -g... (cached) yes
checking for pkg-config... yes
configure: Now testing for NLopt header file.
[...]
checking for nlopt.h... yes
configure: Suitable NLopt library found.
configure: creating ./config.status
config.status: creating src/Makevars
** libs
g++ -I/usr/share/R/include -DNDEBUG -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -O3 -Wall -pipe -Wno-unused -pedantic -c dummy.cpp -o dummy.o
gcc -I/usr/share/R/include -DNDEBUG -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -O3 -Wall -pipe -pedantic -std=gnu99 -c nloptr.c -o nloptr.o
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o nloptr.so dummy.o nloptr.o -lnlopt -lm -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/nloptr/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (nloptr)
The downloaded source packages are in
‘/tmp/downloaded_packages’
edd#max:~$
Note how it compiled only two files from the actual R packages having found the nlopt installation.
I had exactly the same problem, on a production machine without direct Internet access, with Red Hat Enterprise Linux Server release 6.6 (Santiago). The fixups proposed above did not work: when installing the nlopt library on the system, the subsequent attempt to install nloptr fail with the "nlopt_set_maxtime" error. I tried to fiddle with compilation options for nlopt, to no avail. I even reproduced the problem on a Ubuntu machine with Internet connection: I uninstalled nloptr, installed nlopt on the system and then the nloptr installation failed.
At last I solved the issue taking the following steps:
Un-install nlopt from the operating system (make sure that it is thoroughly removed).
Manually download nlopt-2.4.2.tar.gz and copy it to /tmp/
Manually download nloptr_1.0.4.tar.gz to a work directory and unpack it; this creates the directory "nloptr/".
Edit "nloptr/configure", comment out the row
$("${R_HOME}/bin/Rscript" --vanilla -e
"download.file(url='${NLOPT_URL}', destfile='${NLOPT_TGZ}')")
and insert a new row:
$("${R_HOME}/bin/Rscript" --vanilla -e
"file.copy(from='/tmp/nlopt-2.4.2.tar.gz', to='${NLOPT_TGZ}')")
Install with "R CMD INSTALL nloptr".
I had a similar problem on Ubuntu. In addition to installing nlopt-dev as Dirk answered, I also had to install pkg-config:
sudo apt-get install pkg-config
Hope this helps.
If you are on CentOS (and have internet access, but the nlopt server is not reachable), you can install nlopt first using
yum install nlopt nlopt-devel
Then you can install nloptr normally.
I had the same issue setting up nloptr on my RHEL 7.2 instance. For those using RHEL you can do the following:
Download & install the following RPMS in the same order:
NLopt-2.4.2-2.el7.x86_64.rpm- https://pkgs.org/centos-7/epel-x86_64/NLopt-2.4.2-2.el7.x86_64.rpm.html
NLopt-devel-2.4.2-2.el7.x86_64.rpm - https://pkgs.org/centos-7/epel-x86_64/NLopt-devel-2.4.2-2.el7.x86_64.rpm.htm
Please note that these RPMs may need additional dependencies to be installed based on your system configuration.
Post this you can install nloptr directly using the install.packages utility or download source from CRAN and install from source as suggested in earlier responses.
Hope this helps!
Kiran
if you are using AWS Linux the below should help
yum --enablerepo=epel install NLopt-devel -y
I just solved this on my server with following two steps:
Install libnlopt-dev and nlopt with
sudo apt-get install libnlopt-dev
pip install nlopt
Use sudo R to launch R and type:
withr::with_makevars(c(PKG_LIBS='-lnlopt'),install.packages('nloptr'),assignment='+=')
I think I have the same problem as you and I am using CentOS 6.5
Remove nlopt and install nloptr with install.packages() in R, a nlopt will be installed automatically.
I removed installed nlopt with the following command in the unzipped nlopt folder.
make uninstall
If you had tried to use epel repository in CentOS and had installed nlopt with yum, try:
yum remove nlopt
After removing existed nlopt, I am able to install nloptr with
install.packages("nloptr")

Why has my R devtools package load failed?

I am trying to create my first package using the instructions on the hadley devtools wiki. I am using Windows 7 Professional, I have loaded R-tools 3.1, and I am using R 3.0.2. I get the error below when I run the has_devel() command and I do no know why. Does anyone know how I can successfully install devtools given the error below.
has_devel()
"C:/PROGRA~1/R/R-30~1.2/bin/x64/R" --vanilla CMD SHLIB foo.c
Error: Command failed (1)
> traceback()
6: stop("Command failed (", status, ")", call. = FALSE)
5: system_check(r_path, options, c(r_env_vars(), env_vars), ...)
4: force(code)
3: in_dir(path, system_check(r_path, options, c(r_env_vars(), env_vars),
...))
2: R("CMD SHLIB foo.c", tempdir())
1: has_devel()
There is an existing related question, except in that example R is run on MAC OSX (The check for successful devtools load (has_devel) fails).
My Rtools installation was not complete.
I re-installed the most recent version of Rtools from CRAN (http://cran.rstudio.com/). I re-installed devtools using the instructions supplied by Hadley Wickham (http://adv-r.had.co.nz/Philosophy.html) and the error was fixed, has_devel() returned TRUE.
has_devel()
"C:/PROGRA~1/R/R-30~1.2/bin/x64/R" --vanilla CMD SHLIB foo.c
gcc -m64 -I"C:/PROGRA~1/R/R-30~1.2/include" -DNDEBUG -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -std=gnu99 -mtune=core2 -c foo.c -o foo.o
gcc -m64 -shared -s -static-libgcc -o foo.dll tmp.def foo.o -Ld:/RCompile/CRANpkg/extralibs64/local/lib/x64 -Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/PROGRA~1/R/R-30~1.2/bin/x64 -lR
[1] TRUE
see here for the same issue https://github.com/hadley/devtools/issues/234
(solution provided by hadley, running the script in this gist https://gist.github.com/hadley/4506250)
I have installed first time to a directory C:\Apps\Rtools without checking the environmental variable add step during installation. But, I have manually added the path into the PATH variable. Then, I had the same problem.
Then I reinstalled to the default directory C:\Rtools and this time I checked the environmental variable add step during installation. Then it worked.

compiling package with Rcpp outside of R-Studio in Windows

I've successfully build my own package with Rcpp in R-Studio. However, when building the package in the Windows console, there are some error messages complaining file missing of R.h.
I set the path and R_Home environments with
SET PATH=D:\RTools\gcc-4.6.3\bin;D:\R3\bin;D:\RTools\bin;
SET R_HOME=D:\R3\
And the build command is
R CMD INSTALL --byte-compile --build mypkg
Below are the compiling error messages:
g++ -m32 -I"/include" -DNDEBUG -I"D:/R3/library/Rcpp/include" -I"d:
/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -mtune=core2 -c Rcpp
Exports.cpp -o RcppExports.o
In file included from D:/R3/library/Rcpp/include/Rcpp.h:27:0,
from RcppExports.cpp:4:
D:/R3/library/Rcpp/include/RcppCommon.h:35:15: fatal error: R.h: No su
ch file or directory
compilation terminated.
You are missing an include for R.h, as the error says.
And if you look at your compile line, the statement
-I"/include"
is wrong relative to your stated R_HOME in D:/R3
You need to check your setup, somehow you confused R from using the correct include directory.
Rcpp builds just fine on Windows, you can even check by submitting your package to the win-builder service.

Resources