R package installation with gfortran warnings in OSX - r

I have now been searching the web and tried different methods to get a R library (ctsmr) installed from the source, but without luck. I know it works on Linux and Windows, but have not succeeded on my Mac (OSX v10.12.6) with R v3.3.3.
When I try to install it like this:
install.packages("ctsmr", repo="http://ctsm.info/repo/dev", type="source")
I get the some warnings during the installation process, but the installation finishes.
* installing *source* package ‘ctsmr’ ...
** libs
gfortran-4.8 -fopenmp -fPIC -Wall -g -O2 -c fdf.f90 -o fdf.o
gfortran-4.8: warning: couldn’t understand kern.osversion ‘16.7.0
fdf.f90:19.30:
INTEGER I,ISTOP
1
Warning: Unused variable 'istop' declared at (1)
gfortran-4.8 -fPIC -g -O2 -c matutil.f -o matutil.o
gfortran-4.8: warning: couldn’t understand kern.osversion ‘16.7.0
gfortran-4.8 -fPIC -g -O2 -c opkda1.f -o opkda1.o
...
When I run an example in RStudio (the one that is called "Building 1" on the packages webpage, http://ctsm.info) I get an error message for one of the function from the package. (This error message actually does not show up at the moment, as RStudio just crash when I run the line):
fit <- model$estimate(data=X)
Error in dyn.load(x = m$libfile) :
unable to load shared object '/var/folders/7g/81dqdb9s4qq2r79ncggcv2l40000gn/T//RtmpNoNnQl/model5a613c359b3f.so':
dlopen(/var/folders/7g/81dqdb9s4qq2r79ncggcv2l40000gn/T//RtmpNoNnQl/model5a613c359b3f.so, 6): Symbol not found: _GOMP_parallel_end
Referenced from: /var/folders/7g/81dqdb9s4qq2r79ncggcv2l40000gn/T//RtmpNoNnQl/model5a613c359b3f.so
Expected in: dynamic lookup
It looks a little different if I run the same script in the R application:
fit <- model$estimate(data=X)
*** caught illegal operation ***
address 0x7fffa39b0e97, cause 'illegal opcode'
Trackback:
1: dyn.load(x = m$libfile)
2: CallFunction("ctsmdriver", .self, rho, verbose = verbose)
3: model$estimate(data = X)
So, I am wondering if the package is not installed correctly or if their is a bug in the package (maybe because of the double slashes in the path in the error message).
If I manually go look for the shared object, model5a613c359b3f.so, it actually exist on my computer.
Regarding the gfortran compiler I get the following form the therminal:
~ $ gfortran --version
GNU Fortran (GCC) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
~ $ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
I would appreciate if someone could tell me if it is a installation error or a bug in the package. And secondly, come up with possible solutions.

Related

stdio.h not found during r package installation

I have been having some difficulties with my R install. I realised that I was unable to install packages and thought that it was due to having been tinkering with the packages I had installed recently. As I am a novice I thought that a clean install might fix it so I uninstalled R and Rstudio (via homebrew).
On reinstall I'm faced with the same issue. This is part of the console output from
install.packages("tidyverse")
/usr/local/opt/llvm/bin/clang -fopenmp -I"/usr/local/Cellar/r/3.5.1/lib/R/include" -DNDEBUG -I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include -fPIC -g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe -c assumptions.c -o assumptions.o
In file included from assumptions.c:21:
/usr/local/Cellar/r/3.5.1/lib/R/include/Rinternals.h:39:11: fatal error: 'stdio.h' file not found
# include <stdio.h>
^~~~~~~~~
1 error generated.
Searching this site and others suggested that this is to do with lacking the Xcode command line tools. I have checked that these are installed.
Searching for stdio.h in terminal shows numerous versions in the various subfolders (tvos, iOS etc.)
other missing files include: stdlib.h, assert.h and unistd.h
I can provide the full output if that would help
Further searches have identified that in Xcode 10 (as is bundled with macOS Mojave), the location of the standard path for stdio.h and other utilities has moved.
"Legacy software" that looks for the macOS headers in the base system under /usr/include will not find the required files.
To patch this, Xcode includes a package to create links for such software to find the files.
For Xcode 10 the package file is located at:
/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
This information was sourced from the apple Developer forums
After installing this package and restarting the computer I have successfully installed the tidyverse.
I did run into another issue where my C compiler was not able to create executables but this was solved in this thread.

'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.

R package source install, no compiler

I am trying to install some packages from source on a linux (RHEL) server. But whenever the package requires some C++ compilation it fails.
For example, I try to install Ckmeans.1d.dp package. If I call R CMD INSTALL Ckmeans.1.dp_4.2.1.tar.gz I get the following output (truncated) where you can see the compiler is omitted.
...* installing *source* package ‘Ckmeans.1d.dp’ ...
** libs
I/usr/include/R -DNDEBUG -I/usr/local/include -c Ckmeans.1d.dp.cpp -o Ckmeans.1d.dp.o
make: I/usr/include/R: Command not found
...
-shared -L/usr/local/lib64 -o Ckmeans.1d.dp.so Ckmeans.1d.dp.o Ckmeans.1d.dp_main.o dynamic_prog.o fill_SMAWK.o fill_log_linear.o fill_quadratic.o select_levels.o weighted_select_levels.o -L/usr/lib64/R/lib -lR
/bin/sh: line 2: -shared: command not found
make: *** [Ckmeans.1d.dp.so] Error 127
ERROR: compilation failed for package ‘Ckmeans.1d.dp’
I am currently stuck with a server that only has R 3.1.1 and I do not have admin privileges. The $Rhome/etc/Makeconf has CXX and CC defined. I have also verified g++ and gcc are installed.
What could be happening here?
Invariably an environment variable with an 'empty' value gets expanded. Maybe (just guessing here) the package would use C++11, so $(CXX11} -shared gets expanded and ... becomes -shared and an error is triggered.
Look at the R settings, eg via less $(R HOME)/etc/Makevars and see what it expects.
I think you can get by, if you must, installing gcc et al below, say, ~/bin. Some packages will require a compiler...

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