I am the mantainer of few R packages that use Rcpp for some core calculations. Wishing to try a new feature of the Rcpp package as described in Rcpp 0.12.18 Rbloggers
To do so I did the following:
I created a Makevars and Makevars.win in my scr folder, both contaning the line CPPFLAGS += -DRCPP_USE_UNWIND_PROTECT
I added the SystemRequirements: GNU make entry in the DESCRIPTION file.
Btw that raises some issues that I wounder will make my package rejected on CRAN:
following Warning message in compiling my package:
checking compilation flags in Makevars ... WARNING Variables overriding user/site settings: CPPFLAGS: -o /dev/null -DRCPP_USE_UNWIND_PROTECT
Note: GNU make is a system requirement
I would like to know if it is possible to rewrite the Makevars to remove the warning and possibly, the Gnu make requirement
Thanks in advance for the attention
You want to use PKG_CPPFLAGS (or PKG_CXXFLAGS) as that is the per-package variant. What you altered is the system-wide version hence the warning.
More details are as always in the Writing R Extensions manual, otherwise the many existing example packages (all on CRAN and browseable at GitHub) can help too.
For example, here is the one-toggle-setting use case from the RcppExamples package:
PKG_CXXFLAGS = -DRCPP_NEW_DATE_DATETIME_VECTORS
(which is strictly-speaking no longer needed as the "new" Date and Datetime vector classes became the default a while ago).
Also, if you use this form you do not need the += and have no requirement to declare on GNU make -- another win.
Related
When I try to compile R packages from source, it uses the compilers and settings defined in etc/Makeconf within the R installation directory. How can I override these settings?
I have an ~/.R/Makevars file (suggested e.g. here), and I included the settings I want there, but these are not being used for some reason. Why not, and how can I fix this?
I could not find the official documentation on ~/.R/Makevars and Makeconf—links would be welcome.
In the past, this very same setup used to work correctly for me, but recently it doesn't. I assume something must have changed in recent R versions, but I am not sure when. Were there any recent changes that could have affected this?
Motivation and context:
I am on macOS and I want to use gfortran from MacPorts. Thus I set FC = /opt/local/bin/gfortran-mp-11 and FLIBS = -L/opt/local/lib/gcc11 -lgfortran -lquadmath -lm in ~/.R/Makevars. However, the system still wants to use a gfortran installation in /usr/local, which does not exist on my machine. It clearly takes the paths and options from etc/Makeconf. I am using the official R binaries.
It turns out that the reason why ~/.R/Makevars was ignored on my machine when trying to build a certain package was a bug in withr:
https://github.com/r-lib/withr/issues/169
Installing the development version of withr using devtools::install_github("r-lib/withr#master") fixed the problem.
Situation:
The R package I am developing exports a C function through R's .C.
The code in src/ where the function is defined compiles fine if libtiff is installed in the OS.
I'd like this functionality to be optional; just as there are "suggested" R packages, because it is not essential.
The problem
I found no way to tell R that a C function compilation is "suggested". Neither could I find a way to make compilation of code in src/ optional, or conditional to the presence of libtiff in the OS in some way.
My current Makevars says:
CC=ccache clang -Qunused-arguments
CXX=ccache clang++ -Qunused-arguments
CCACHE_CPP2=yes
PKG_LIBS = -ltiff
I have been searching for a solution all day, without success.
I've only just figured out how to use Makevars to look for libtiff:
TIFFSTATUS := $(shell $(LD) -ltiff; echo 0 || echo 1)
ifeq ($(TIFFSTATUS), 1)
... stuff?
The question
How can I properly tell R that a function using .C is optional (ie conditional to the availability of the libtiff dependencies).
Thanks.
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
I have released an R package on CRAN which depends on the successful compilation of some RcppArmadillo code. The package built correctly and with no notes on all the test systems that I tried (CRAN comments here if interested), however, the CRAN checks fail on solaris-sparc and are unable to load a dependency on solaris-x86.
See here for CRAN checks.
The reason for the error is given as ld: fatal: library -llapack: not found (from goldi-00install.html).
In my Makevars and Makevars.win, I have stated -llapack in PKG_LIBS, which I thought was sufficient.
PKG_LIBS= -Wsign-compare -llapack in both.
However, I'm unsure how to declare this dependency for Solaris. Is there a separate Makevars that I must write, or there a different location that I must state the dependency?
I have read the relevant section of the "Writing R Extensions" manual, and suspect that I may have to declare $(LLAPACK_LIBS) in PKG_LIBS, but have no way of testing it on a solaris platform. Is this the correct path to follow?
Thanks for any help, it's much appreciated.
Package on Github
Package on CRAN
Your line in src/Makevars is just wrong. Don't do what you did:
PKG_LIBS= -Wsign-compare -llapack
do what we all do, what the example package has and the what the auto-generated package gets:
PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
Believe us when we say that it just works. I venture that among the two-hundred-ninenty-one (291 !!) packages on CRAN, essentially all use this.
And any who do not, like yours, simply do it wrong. The above dispatches to what R knows about LAPACK and its dependencies. Use it.
When developing a package one can run R CMD check, which helpfully tells you any problems in your code (syntax errors, unstated dependencies, undefined variables).
Does a utility exist that will provide this functionality of R CMD check for individual source files?
I could create an empty package and move source files in their to check them, but that's both a pain, and overkill.
It sounds like you want to look at the codetools package.