Search code examples
rcygwin

Build R package in Windows under Cygwin


When trying to update R package dplyr to 0.7.0 from source on Win10 under Cygwin (windows binary for dplyr 0.7.0 is not available. Also my R installation in not under Cygwin and my R installation is from binary). However when I run

R CMD INSTALL dplyr_0.7.0.tar.gz

see the following error:

* installing to library 'C:/Program Files/R/R-3.4.0/library'
* installing *source* package 'dplyr' ...
** package 'dplyr' successfully unpacked and MD5 sums checked
** libs
c:/Rtools/mingw_64/bin/g++  -I"C:/PROGRA~1/R/R-34~1.0/include" -DNDEBUG    -I../inst/include -DCOMPILING_DPLYR -DRCPP_USING_UTF8_ERROR_STRING -I"C:/Program Files/R/R-3.4.0/library/Rcpp/include" -I"C:/Program Files/R/R-3.4.0/library/BH/include" -I"C:/Program Files/R/R-3.4.0/library/bindrcpp/include" -I"C:/Program Files/R/R-3.4.0/library/plogr/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c   RcppExports.cpp -o RcppExports.o
/bin/sh: c:/Rtools/mingw_64/bin/g++: No such file or directory
make: *** [C:/PROGRA~1/R/R-34~1.0/etc/x64/Makeconf:215: RcppExports.o]    Error 127
Warning: running command 'make -f "Makevars.win" -f "C:/PROGRA~1/R/R -34~1.0/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-34~1.0/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="dplyr.dll" WIN=64 TCLBIN=64 OBJECTS="RcppExports.o address.o api.o arrange.o between.o bind.o combine_variables.o distinct.o filter.o group_by.o group_indices.o hybrid.o hybrid_count.o hybrid_debug.o hybrid_in.o hybrid_minmax.o hybrid_nth.o hybrid_offset.o hybrid_simple.o hybrid_window.o init.o init_register.o join.o join_exports.o mutate.o rlang-export.o select.o set.o slice.o summarise.o test.o utils.o window.o"' had status 2
ERROR: compilation failed for package 'dplyr'
* removing 'C:/Program Files/R/R-3.4.0/library/dplyr'
* restoring previous 'C:/Program Files/R/R-3.4.0/library/dplyr'

The cause of error is R (using Rtools library) looks for g++/gcc compilers under c:/Rtools/mingw_64/bin/ and not under Cygwin /usr/bin/

Is there a way to change this default behavior of R CMD INSTALL which would allow building R packages from source in Windows without Rtoools?

Thanks

PS. I think this post how do you use cygwin to compile an R package from source? is relevant, but it appears R was installed under Cygwin, which is not my case.

PPS. It appears I need to change variables defined under

R CMD config

Any ideas how?


Solution

  • I'm not sure what the best solution is. But you can certainly fix this by modifying BINPREF in $(R_HOME)/etc/x64/Makeconf. c:/Rtools/mingw_64/bin/ is the default value.

    PS: You almost certainly can use the cygwin compiler to build R packages, as long as only C linkage is involved. I build some of mine under Visual Studio.