rhub compilation warning on Ubuntu 16.04 - r

We are developing an R package that contains compiled code (using Rcpp). We check the package builds on rhub (to test builds on multiple platforms) with check_for_cran() function.
For Ubuntu 16.04, we get the following warning
* checking compilation flags used ... WARNING
Compilation used the following non-portable flag(s):
'-Wdate-time' '-Werror-format-security' '-Wformat'
We currently do not have a Makevars file in the src sub directory. To suppress the warnings, we added the -Wall flag in the Makevars file, which results in the following warning
* checking compilation flags in Makevars ... WARNING
Variables overriding user/site settings:
CFLAGS: -Wall
We tried multiple settings of Makevars, but could not get rid of these warnings. We would appreciate any help.
For submission on cran, we need to be able to build the package without any warnings.

Related

R: Error installing GWmodel package from source in R-4.1.1

I am trying to install the package GWmodel from source following this website. After running install_github(lbb220/GWmodel/GWmodel) I am receiving this error: Error: Failed to install 'unknown package' from GitHub: Line starting '<<<<<<< HEAD ...' is malformed!
The reason I want to to install the package from source and not use the install.packages("GWmodel") is that I want to use parallel.method = "cuda". In the documentation it says:
Requirements of using CUDA for high-performence computation in GWR functions:
To run GWR-CUDA (i.e. parallel.method is pecified as “cuda”) with gwr.basic , bw.gwr and gwr.model.selection, the following conditions are required:
There is at least one NVIDIA GPU supporting CUDA equipped on user's computer.
CUDA (>10.2) are installed with the environment variable 'CUDA_HOME' set properly.
The package should re-built from source. - For Linux user, 'GWmodelCUDA' will be automatically built if CUDA toolkit could be detected by the complier. - For Windows user, 'GWmodelCUDA.dll' and 'GWmodelCUDA.lib' will be automatically downloaded; however, we would recommend users to build the 'GWmodelCUDA' library manually to avoid some potentially unknown issues, and an 'CMakeLists.txt' file is provided for this procedure.
If any condition above is not satisfied, the GWR-CUDA will not work even though the “parallel.method” is specified as “cuda”.
If I install it using install.github() I am getting the error I mentioned. I have installed the CUDA (>10.2) and I have set the environment variable 'CUDA_HOME' properly.
If I use the install.packages("GWmodel") I get no errors. I also tried to download GWmodel.zip and install from a local zip file, but the same error.
I have install rtools successfully (I tested it using the example here)
I am using R.Studio 1.4.1717, R 4.1.1 and Windows 11.
Any ideas how can I proceed?
I used install_github("lbb220/GWmodel") and although I don't receive the above error, still the installation cannot be done. I am getting the below message now:
** libs
*** arch - i386
"C:/rtools40/mingw32/bin/"g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-41~1.1/include" -DNDEBUG -I'C:/Program Files/R/R-4.1.1/library/Rcpp/include' -I'C:/Program Files/R/R-4.1.1/library/RcppArmadillo/include' -ARMA_64BIT_WORD=1 -fopenmp -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c GWmodel.cpp -o GWmodel.o
GWmodel.cpp: In function 'double sp_gcdist(double, double, double, double)':
GWmodel.cpp:764:29: error: 'DOUBLE_EPS' was not declared in this scope
if (fabs(lat1 - lat2) < DOUBLE_EPS) {
^~~~~~~~~~
GWmodel.cpp:764:29: note: suggested alternative: 'ENABLE_NLS'
if (fabs(lat1 - lat2) < DOUBLE_EPS) {
^~~~~~~~~~
ENABLE_NLS
GWmodel.cpp: In function 'void printMat(arma::mat)':
GWmodel.cpp:1165:16: warning: comparison of integer expressions of different signedness: 'const uword' {aka 'const unsigned int'} and 'int' [-Wsign-compare]
if (m.n_rows < n)
~~~~~~~~~^~~
make: *** [C:/PROGRA~1/R/R-41~1.1/etc/i386/Makeconf:245: GWmodel.o] Error 1
ERROR: compilation failed for package 'GWmodel'
* removing 'C:/Program Files/R/R-4.1.1/library/GWmodel'
Warning message:
In i.p(...) :
installation of package ‘C:/Users/GEOGRA~1/AppData/Local/Temp/RtmpOwWBPs/file8f43609514d/GWmodel_2.2-0.tar.gz’ had non-zero exit status
This is because you are not actually installing from the main repository. Try install_github(lbb220/GWmodel).

semPlot won't install in R/Rstudio on MacOS 11.4 because OpenMx won't install & it's a dependency

I'm running R 3.6.1 in an Anaconda environment (it won't let me upgrade to v4) and trying to install semPlot to accompany lavaan which installed fine. Here are the packages I've installed:
library(psych) # for Chronbach's alpha calculation
library(psychTools)
library(lavaan)
library(knitr)
library(tidyverse)
library(haven)
library(labelled)
library(kableExtra)
library(survey)
library(srvyr)
library(scales)
I've tried many different ways to install semPlot, the latest was directly from the github repository: SachaEpskamp/semPlot, which one person on stackoverflow said worked for them. After about 10,000 lines of warnings and errors scrolling across my console so fast I couldn't track much of it, this latest attempt produced this at the end:
The downloaded source packages are in
‘/private/var/folders/8_/ql9yb6nn4076n1y9vptzpqwm0000gp/T/RtmpvagRhg/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
✓ checking for file ‘/private/var/folders/8_/ql9yb6nn4076n1y9vptzpqwm0000gp/T/RtmpvagRhg/remotes164e53982f159/SachaEpskamp-semPlot-a2ee9df/DESCRIPTION’ ...
─ preparing ‘semPlot’:
✓ checking DESCRIPTION meta-information ...
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
─ building ‘semPlot_1.1.4.tar.gz’
ERROR: dependency ‘OpenMx’ is not available for package ‘semPlot’
* removing ‘/Users/sjgenco/opt/anaconda3/envs/r_env/lib/R/library/semPlot’
Warning messages:
1: In i.p(...) : installation of package ‘OpenMx’ had non-zero exit status
2: In i.p(...) :
installation of package ‘/var/folders/8_/ql9yb6nn4076n1y9vptzpqwm0000gp/T//RtmpvagRhg/file164e543b3278e/semPlot_1.1.4.tar.gz’ had non-zero exit status
I don't know if OpenMx is the culprit or if OpenMX and semPlot may be suffering from the same problem, but I get the same sort of result when I try to install it ... thousands of lines (and about 20 minutes of fruitless runtime) before it just peters out, not with any kind of error, just a "nonzero exit status".
I've read lots of similar questions here on SO, but most have some dependent package not being found, like glasso or XML a missing fortran compiler, but I have no references like that in my output and I have all those packages installed anyway. I just have reams of output like this (this is from a failed OpenMx installation attempt:
In file included from povRAM.cpp:2:
In file included from ./omxExpectation.h:32:
In file included from ./omxDefines.h:21:
In file included from /Users/xxxxxxxxx/opt/anaconda3/envs/r_env/lib/R/library/Rcpp/include/Rcpp.h:27:
In file included from /Users/xxxxxxxxx/opt/anaconda3/envs/r_env/lib/R/library/Rcpp/include/RcppCommon.h:120:
In file included from /Users/xxxxxxxxx/opt/anaconda3/envs/r_env/lib/R/library/Rcpp/include/Rcpp/proxy/proxy.h:22:
/Users/xxxxxxxxx/opt/anaconda3/envs/r_env/lib/R/library/Rcpp/include/Rcpp/proxy/NamesProxy.h:32:21: warning: definition of implicit copy constructor for 'NamesProxy' is deprecated because it has a user-declared copy assignment operator [-Wdeprecated-copy]
NamesProxy& operator=(const NamesProxy& rhs) {
^
/Users/xxxxxxxxx/opt/anaconda3/envs/r_env/lib/R/library/Rcpp/include/Rcpp/proxy/NamesProxy.h:83:16: note: in implicit copy constructor for 'Rcpp::NamesProxyPolicy<Rcpp::Vector<19, PreserveStorage> >::NamesProxy' first required here
return NamesProxy( static_cast<CLASS&>(*this) ) ;
^
/Users/xxxxxxxxx/opt/anaconda3/envs/r_env/lib/R/library/Rcpp/include/Rcpp/api/meat/module/Module.h:35:11: note: in instantiation of member function 'Rcpp::NamesProxyPolicy<Rcpp::Vector<19, PreserveStorage> >::names' requested here
info.names() = names ;
^
In file included from povRAM.cpp:3:
In file included from ./path.h:6:
./polynomial.h:26:2: warning: definition of implicit copy assignment operator for 'Monomial<double>' is deprecated because it has a user-declared copy constructor [-Wdeprecated-copy]
Monomial(const Monomial<F> &from) { coeff = from.coeff; exponent = from.exponent; }
^
/Users/xxxxxxxxx/opt/anaconda3/envs/r_env/bin/../include/c++/v1/__tree:1691:39: note: in implicit copy assignment operator for 'Monomial<double>' first required here
__cache.__get()->__value_ = *__first;
^
/Users/xxxxxxxxx/opt/anaconda3/envs/r_env/bin/../include/c++/v1/__tree:1648:9: note: in instantiation of function template specialization 'std::__1::__tree<Monomial<double>, std::__1::less<Monomial<double> >, std::__1::allocator<Monomial<double> > >::__assign_multi<std::__1::__tree_const_iterator<Monomial<double>, std::__1::__tree_node<Monomial<double>, void *> *, long> >' requested here
__assign_multi(__t.begin(), __t.end());
^
/Users/xxxxxxxxx/opt/anaconda3/envs/r_env/bin/../include/c++/v1/set:538:21: note: in instantiation of member function 'std::__1::__tree<Monomial<double>, std::__1::less<Monomial<double> >, std::__1::allocator<Monomial<double> > >::operator=' requested here
__tree_ = __s.__tree_;
^
./polynomial.h:183:13: note: in instantiation of member function 'std::__1::set<Monomial<double>, std::__1::less<Monomial<double> >, std::__1::allocator<Monomial<double> > >::operator=' requested here
monomials = erg.monomials;
^
povRAM.cpp:299:16: note: in instantiation of member function 'Polynomial<double>::operator+=' requested here
polyRep[nn] += term;
^
95 warnings and 7 errors generated.
make: *** [/Users/xxxxxxxxx/opt/anaconda3/envs/r_env/lib/R/etc/Makeconf:175: povRAM.o] Error 1
ERROR: compilation failed for package ‘OpenMx’
* removing ‘/Users/xxxxxxxxx/opt/anaconda3/envs/r_env/lib/R/library/OpenMx’
Warning in install.packages :
installation of package ‘OpenMx’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/8_/ql9yb6nn4076n1y9vptzpqwm0000gp/T/Rtmp8fpYnY/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
A warning that comes up again and again in all these outputs is this:
warning: definition of implicit copy constructor ...
as in:
/Users/xxxxxxxxx/opt/anaconda3/envs/r_env/lib/R/library/Rcpp/include/Rcpp/proxy/NamesProxy.h:32:21: warning: definition of implicit copy constructor for 'NamesProxy' is deprecated because it has a user-declared copy assignment operator [-Wdeprecated-copy]
NamesProxy& operator=(const NamesProxy& rhs) {
^
or this
/Users/xxxxxxxxx/opt/anaconda3/envs/r_env/lib/R/library/Rcpp/include/Rcpp/proxy/AttributeProxy.h:33:25: warning: definition of implicit copy constructor for 'AttributeProxy' is deprecated because it has a user-declared copy assignment operator [-Wdeprecated-copy]
AttributeProxy& operator=(const AttributeProxy& rhs){
^
or this
/Users/xxxxxxxxx/opt/anaconda3/envs/r_env/lib/R/library/RcppEigen/include/Eigen/src/SparseCore/SparsePermutation.h:162:1: note: candidate template ignored: could not match 'InverseImpl' against 'Transpose'
operator*(const SparseMatrixBase<SparseDerived>& matrix, const InverseImpl<PermutationType, PermutationStorage>& tperm)
^
povRAM.cpp:157:24: error: use of undeclared identifier 'curProd'
if (tx == 1) prev = curProd.nonZeros();
^
This is just a big mess and I have no idea what's happening, why, or what to do about it. Any thoughts?
Your problems are likely caused by running R through Anaconda. Following these steps I successfully install OpenMX and semPlot without error on macOS 11.4 / Rv4.0, but you'll have to try it to find out if they will work on 'conda' R3.6.3.
Install xcode from the app store (instructions for installing xcode) then install/reinstall the xcode command line tools from the terminal:
# To delete an existing command line tools installation:
sudo rm -rf /Library/Developer/CommandLineTools
# To install the command line tools
sudo xcode-select --install
Install gcc & llvm via Homebrew (instructions for installing Homebrew) or, if you already have gcc and llvm installed, skip to step 3.
# WARNING: This can take several hours
brew install gcc
brew install llvm
If you already have gcc & llvm installed via Homebrew:
brew cleanup
brew update
brew upgrade
brew reinstall gcc
brew reinstall llvm
Link some headers into /usr/local/include
sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/
# You can ignore warnings like this:
#ln: /usr/local/include//tcl.h: File exists
#ln: /usr/local/include//tclDecls.h: File exists
#ln: /usr/local/include//tclPlatDecls.h: File exists
#ln: /usr/local/include//tclTomMath.h: File exists
#ln: /usr/local/include//tclTomMathDecls.h: File exists
#ln: /usr/local/include//tk.h: File exists
#ln: /usr/local/include//tkDecls.h: File exists
#ln: /usr/local/include//tkPlatDecls.h: File exists
Check your version of gfortran (cd /usr/local/gfortran/lib/gcc/x86_64-apple-darwin19/; ls) then edit your ~/.R/Makevars file (if you don't have a file called Makevars in your ~/.R/ directory, or the 'conda' R equivalent directory, create it) and include only these lines:
LOC = /usr/local/gfortran
CC=$(LOC)/bin/gcc -fopenmp
CXX=$(LOC)/bin/g++ -fopenmp
CXX11 = $(LOC)/bin/g++ -fopenmp
CFLAGS=-g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-g -O3 -Wall -pedantic -std=c++11 -mtune=native -pipe
LDFLAGS=-L$(LOC)/lib -Wl,-rpath,$(LOC)/lib
CPPFLAGS=-I$(LOC)/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
# (check that the version of gfortran - in this case 10.2.0 - matches the version specified in FLIBS)
FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin19/10.2.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
CXX1X=/usr/local/gfortran/bin/g++
CXX98=/usr/local/gfortran/bin/g++
CXX11=/usr/local/gfortran/bin/g++
CXX14=/usr/local/gfortran/bin/g++
CXX17=/usr/local/gfortran/bin/g++
Open R and install the packages (when asked, compile from source = "Yes"):
install.packages("qgraph")
install.packages("OpenMx")
devtools::install_github("SachaEpskamp/semPlot")
Then, hopefully, things will load as they are supposed to.
Thank you for this detailed advice. First I tried to fix it inside my Anaconda environment by running the conda forge installation in my r_env from the terminal. It installed, but it also managed to break my RStudio installation so that wouldn't open anymore. OK, lesson learned. I deleted my whole r_env in Anaconda and proceeded to follow #MrFlick's advice to install clean new versions of R and RStudio from their official download sites. When I opened my fresh RStudio app, I was able to install semPlot, which installed its dependency OpenMx without a hitch. Back in business.

Rcpp fails to compile c++ code after series of updates

I'd like to keep my OS, R, and R packages up to date. I unknowingly treaded into deep water by upgrading to OSX 10.15.6 and upgrading to R 4.0.2. Currently, Rcpp is failing to compile c++ code, which I believe is causing the CRAN installation for certain packages to fail (e.g. glmmTMB), and is also causing installations from source to fail. I'll describe what I've done and hopefully someone can elucidate a solution.
In a rough order, here's what I've done:
Installed OSX 10.15.6
I don't remember the date but it was fairly recent. I don't know how closely this is related to the problem, I was having issues installing other R packages (e.g. rstan) that needed Rcpp prior to this.
Ran into an issue trying to run some old glmmTMB models
The exact error was identical to this issue. I followed the various solutions on that thread to no avail. Perhaps the most frustrating was when attempting to install from source, which then failed to compile some c++.
This wasn't the first time I had seen similar errors. Something similar happened when I tried installing rstan, so I asked for some help on their repo under a similar issue. Nothing helped.
This was on R 3.6, so I thought maybe it'd be worth updating R and glmmTMB. Before doing this I wanted to install Xcode, as opposed to just the Command Line Developer Tools, in hopes that the installation would ensure I'd have everything clang- and c++ compiler-related squared away.
Installed Xcode to help set a baseline c++ environment
Relatively painless, am able to build and compile fairly simple c++ projects.
Installed R 4.0.2
From the r-project site, I installed R-4.0.2.pkg without issues and with the default install settings. According to the R project Tools site, I was reassured in installing Xcode and continued on to install the GNU Fortran 8.2 installer.
Followed #coatless's guide to installing Rcpp
Discovered this guide and followed each step, except for those related to xcode-select.
Testing Rcpp and RcppArmadillo from the guide
One of the last steps is to test the installation with a simple helloworld.cpp test. This fails with this error (abridged for clarity):
> Rcpp::sourceCpp("~/Documents/BergenLab/nlp_cancer_metaphor/helloworld.cpp")
In file included from helloworld.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/RcppArmadillo.h:31:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/RcppArmadilloForward.h:26:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/RcppCommon.h:29:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/Rcpp/r/headers.h:67:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:100:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:317:9: error: no member named 'signbit' in the global namespace
using ::signbit;
~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [helloworld.o] Error 1
clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I../inst/include -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include" -I"/Users/alex/Documents/BergenLab/nlp_cancer_metaphor" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -c helloworld.cpp -o helloworld.o
Error in Rcpp::sourceCpp("~/Documents/BergenLab/nlp_cancer_metaphor/helloworld.cpp") :
Error 1 occurred building shared library.
Tried to debug Rcpp to no avail
Found some somewhat related reports, such as Packages cannot build from source due to math.h not found, Rcpp doesn't under macOS, math.h not found, Source Cpp file failed due to math.h not found, and Cannot compile R packages with c++ code after updating to macOS Catalina.
None of the solutions in these answers have helped at all. The only solution which gave me feedback was using installer to install macOS_SDK_headers_for_macOS_10.14.pkg which subsequently gave me installer: Error - the package path specified was invalid (not sure how what the implications of this are).
Installing glmmTMB from source fails
One of the solutions from an above glmmTMB issue recommends installing from source. Here is the error on my attempt:
* installing *source* package ‘glmmTMB’ ...
** package ‘glmmTMB’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include' -I'/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include' -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -c glmmTMB.cpp -o glmmTMB.o
In file included from glmmTMB.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/TMB.hpp:53:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Core:96:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/complex:245:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:317:9: error: no member named 'signbit' in the global namespace
using ::signbit;
~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
13 warnings and 20 errors generated.
make: *** [glmmTMB.o] Error 1
ERROR: compilation failed for package ‘glmmTMB’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/glmmTMB’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/glmmTMB’
Warning in install.packages :
installation of package ‘glmmTMB’ had non-zero exit status
Overall, I'm still unable to run my glmmTMB models (and I presume unable to build rstan as well). Something with my c++ compiler must be off but I'm a c++ beginner and am unsure how to interpret the errors I'm getting. Something's wrong with the header files, but it seems perhaps like it's not due to math.h being missing (like most other posts). It should go without saying but any help would be greatly appreciated!
Edit 1
I've tried to narrow down the error and thus followed each step from #coatless's guide, exactly as listed there and according to the R installation documentation. My exact steps:
Removed gfortran 8.2. Removed ~/.Renviron and ~/.R/Makevars. Unlinked both of these files from Rstudio with unlink().
Ran xcode-select --install, which returned with "use "Software Update" to install updates." Accordingly, softwareupdate --list estimated that nothing needed updating. Regardless, I uninstalled Command Line Tools with sudo rm -rf /Library/Developer/CommandLineTools and installed the Command Line Tools with xcode-select —install. Up to this point everything is working as expected. Small c++ programs are being compiled without issue by both gcc and clang++.
According to the R manual, from https://mac.r-project.org/libs-4/, I installed pcre2-10.34-darwin.17-x86_64.tar.gz, xz-5.2.4-darwin.17-x86_64.tar.gz , and readline-5.2.14-darwin.17-x86_64.tar.gz to /usr/local. No big issues here, although I'm not really sure how to verify that these work as expected.
Restarted an R session in RStudio.
Installed Rcpp and RcppArmadillo with install.packages(c(‘Rcpp’, ‘RcppArmadillo’))
Created a ~/helloworld.cpp with the code from Slide 15 mentioned in the comments.
Running Rcpp::sourceCpp("~/helloworld.cpp") fails with the exact error as mentioned in the body of the post. Similarly evalCpp() fails with a similar error.
After a bit of digging, the issue turned out to be neither glmmTMB, Rcpp, or really anything high-level. From what I understand: When R uses Rcpp to compile c++ code, a certain set of arguments are passed to the system c++ compiler. In my case this compiler was clang++ since I had just installed Xcode. The c++ compiler relies on a set of c++ header files to be included in exactly the right order. Seemed like the order of mine were incorrect, thus causing a slew of errors regarding "missing template definitions."
I looked into changing the order of the includes but couldn't find any straightforward solution. I knew that Rcpp was calling a very specific array of arguments to clang++, so I looked into how that might elucidate an answer. I looked into the manuals for clang++ to figure out what -isysroot and -I meant and felt like they might play a part in reconfiguring how the system header files were being compiled. From one of the threads below I discovered the $(R RHOME)/etc/Makeconf Makefile and proceeded to change the directory of the OSX SDK from what I believe was the Command Line Tools path to the Xcode path. This seemed to solve the issue.
Some threads I used to find this solution: Cannot compile R packages with c++ code after updating to macOS Catalina and Catalina C++: Using <cmath> headers yield error: no member named 'signbit' in the global namespace.
What worked for me:
Note the current header file search
From clang++ -Wp,-v -E -:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.3/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
Note the OSX SDK path
From xcrun --show-sdk-path:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
Modify the R configuration
With vim $(R RHOME)/etc/Makeconf, changed the CPPFLAGS flag to:
CPPFLAGS = -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I/usr/local/include
Notice how this SDK directory is what was found in step 2. This apparently cleans up the location and order of the SDK header file includes.
Reinstall glmmTMB from source
I was still seeing a FreeADFunObject error when trying to fit a glmmTMB model, so I went back to this GH thread and followed the first suggestion: to reinstall from source. This wasn't working before since I needed a properly set up c++ configuration, which I fixed in the last two steps.
Hence, install.packages("glmmTMB", type="source") installed without issue and I can now build and fit glmmTMB models.
For posterity's sake:
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/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

ld: unknown option: -platform_version when building R packages from source

Certain R packages, such as mgcv, fail to compile from source with clang 10+ (under macOS 10.14 and R version 3.6+). The error reported during compilation is
ld: unknown option: -platform_version
How do I resolve this error and compile these packages?
The problem with ld is the same as in Clang 10 fails to link C++ application with CMake on macOS 10.12. However, the suggestion to add the flag -DCMAKE_CXX_FLAGS="-mlinker-version=305" is not applicable to the R package compilation process. For R, you need to add -mlinker-version=305 to LDFLAGS to your Makevars file, typically located in $HOME/.R/.
My Makevars is based on this GitHub gist. I changed LDFLAGS from this:
LDFLAGS+=-L$(HO)/llvm/lib -Wl,-rpath,$(HO)/llvm/lib
to this:
LDFLAGS+=-L$(HO)/llvm/lib -Wl,-rpath,$(HO)/llvm/lib -mlinker-version=305
That resolved the ld error when compiling mgcv from source.
For the igraph package, adding the mlinker flag to LDFLAGS was not enough; it had to be added to the C++ flags as well. In the gist Makevars above, this is done by adding -mlinker-version=305 to STD_FLAGS, which then adds the flag to CXX**FLAGS for all C++ versions.
UPDATE, June 24 2020: unfortunately, some packages (rJava in my case) fail to use the STD_FLAGS. My workaround was to put the mlinker flag in the C compiler invocation:
CC=$(CCACHE) $(HO)/llvm/bin/clang -mlinker-version=305

When building R package, devtools::check() throw 'Permission Denied' error

Over the past years, I built a R package and regularly updated it in Windows 7 Enterprise. Everything was working fine until November 2017 when the company upgraded my desktop. I got a brand new machine with windows 10. As 'permission' issue is kind of common, so I as usual installed R, Rstudio, Rtools into a folder I have write access. But when I tried to build the package in Rstudio, I got the below error:
==> devtools::check()
Updating RCfun documentation
Loading RCfun
Setting env vars --------------------------------------------------------------
CFLAGS : -Wall -pedantic
CXXFLAGS: -Wall -pedantic
Building RCfun ----------------------------------------------------------------
"C:/R/R-34~1.2/bin/x64/R" --no-site-file --no-environ --no-save --no-restore \
--quiet CMD build "Z:\_R\R_package\RCfun" --no-resave-data --no-manual
* checking for file 'Z:\_R\R_package\RCfun/DESCRIPTION' ... OK
* preparing 'RCfun':
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* looking to see if a 'data/datalist' file should be added
* building 'RCfun_0.1.1.tar.gz'
Warning in gzfile(tarfile, "wb", compression = compression_level) :
cannot open compressed file 'C:/Windows/System32/RCfun_0.1.1.tar.gz',
probable reason 'Permission denied'
Error in gzfile(tarfile, "wb", compression = compression_level) :
cannot open the connection
Execution halted
Error: Command failed (1)
Execution halted
Exited with status 1.
Clearly, I don't have access to the folder 'C:/Windows/System32/'. I can't change that and I am aware of that, so I installed R related stuff all in a folder I have access to. But the question is, why it still attempts to write the file RCfun_0.1.1.tar.gz into the folder 'C:/Windows/System32/' when building the package? Where can I change/overwrite that behavior?
I have searched for answers from time to time for the past a couple of month, but got no luck. I found something similar in this thread:
permission denied error while building/checking R package on WIndows
but it doesn't solve my case.
I know it must be related to some system path that directs to this folder 'C:/Windows/System32/'. I tried Sys.setenv(PATH=) to remove that folder. I'm not sure if that's the correct way, but it doesn't help anyway. Is there a way that I can catch where it goes wrong? Thanks.

Resources