Categories: R

Building R on Windows

Building R from Source

In the last post on Installing R, my inability to successfully launch RStudio got me curious about building the product myself since it is open source. I chased the link from The Comprehensive R Archive Network (rstudio.com) to R: The R Project for Statistical Computing (r-project.org), which has a link to the contibutor development site R Development Guide (r-project.org). Chapter 2 R Patched and Development Versions | R Development Guide (r-project.org) has detailed instructions on how to build the sources. I install TortoiseSVN then download rtools42-5355-5357.exe. Looks like it’s just an MSYS2 installation.

Installing MiKTeX

I also follow the instructions and install MiKTeX and check for updates. The process is detailed at Install MiKTeX on Windows. I had some trouble getting the MiKTeX installer to work when installing for all users so I end up installing for just myself but place it in c:\software because I find the user-specific paths too obnoxious.

I was expecting to have TeXnicCenter installed but that is just an editor and it would have required MiKTeX as well. It is not required for building R but I install it anyway (since I usually typeset a lot of personal PDFs such as course assignments/reports).

Environment Setup

I run this command to ensure all programs can be found which make gcc pdflatex tar. However, I did this before step 6: Add gcc, MiKTeX and tar to the PATH and set one tar option.

/usr/bin/make
which: no gcc in (/usr/local/bin:/usr/bin:/bin:/opt/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/c/progra~1/git/cmd:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)
which: no pdflatex in (/usr/local/bin:/usr/bin:/bin:/opt/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/c/progra~1/git/cmd:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)
/usr/bin/tar

This output is interesting because it reminds me of my search for gcc in the MSYS environment when trying to build octave (see Building Octave on Windows)! This is the environment I use on my machine:

export PATH="/x86_64-w64-mingw32.static.posix/bin:$PATH"
export PATH="/c/software/MiKTeX/miktex/bin/x64:$PATH"
export TAR="/usr/bin/tar"
export TAR_OPTIONS="--force-local"

Downloading the latest recommended packages by running "$TOP_SRCDIR/tools/rsync-recommended" outputs the info below.

receiving incremental file list
KernSmooth_2.23-20.tar.gz
MASS_7.3-58.1.tar.gz
Matrix_1.5-3.tar.gz
boot_1.3-28.1.tar.gz
class_7.3-20.1.tar.gz
cluster_2.1.4.tar.gz
codetools_0.2-18.tar.gz
foreign_0.8-84.tar.gz
lattice_0.20-45.tar.gz
mgcv_1.8-41.tar.gz
nlme_3.1-161.tar.gz
nnet_7.3-18.tar.gz
rpart_4.1.19.tar.gz
spatial_7.3-15.1.tar.gz
survival_3.4-0.tar.gz

sent 419 bytes  received 13,176,494 bytes  2,395,802.36 bytes/sec
total size is 13,169,596  speedup is 1.00
Creating links

Building R

Building R and the recommended packages takes 10m 27sec on my AMD Ryzen 7 5800X 8-Core Processor.

make all recommended

The code ends with

...
gcc  -I"C:/Users/saint/repos/R/include" -DNDEBUG     -I"C:/dev/software/rtools42/x86_64-w64-mingw32.static.posix/include"  -fopenmp   -O2 -Wall  -std=gnu99 -mfpmath=sse -msse2 -mst
ackrealign  -c tprs.c -o tprs.o
gcc -shared -s -static-libgcc -o mgcv.dll tmp.def coxph.o davies.o discrete.o gdi.o init.o magic.o mat.o matrix.o mgcv.o misc.o mvn.o ncv.o qp.o soap.o sparse-smooth.o sparse.o tpr
s.o -LC:/Users/saint/repos/R/bin/x64 -lRlapack -LC:/Users/saint/repos/R/bin/x64 -lRblas -lgfortran -lm -lquadmath -fopenmp -LC:/dev/software/rtools42/x86_64-w64-mingw32.static.posi
x/lib/x64 -LC:/dev/software/rtools42/x86_64-w64-mingw32.static.posix/lib -LC:/Users/saint/repos/R/bin/x64 -lR
installing to C:/Users/saint/repos/R/library/mgcv/libs/x64
** R
** data
** inst
** tests
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (mgcv)

I find it strange that the code uses gnu99.

gcc -std=gnu99 -I. -I../include -DHAVE_CONFIG_H -DR_DLL_BUILD -DR_ARCH='"x64"' -O3 -Wall -pedantic -mfpmath=sse -msse2 -mstackrealign    -c eval.c -o eval.o

Running make check takes 3 minutes on my machine and ends with this output:

...
running tests of plotting Latin-1
  expect failure or some differences if not in a Latin-1 or UTF-8 locale
running code in 'reg-plot-latin1.R' ... OK
  comparing 'reg-plot-latin1.pdf' to './reg-plot-latin1.pdf.save' ... OK
running code in 'reg-S4.R' ... OK
  comparing 'reg-S4.Rout' to './reg-S4.Rout.save' ... OK
running tests of Internet functions
running code in 'internet.R' ... OK
  comparing 'internet.Rout' to './internet.Rout.save' ... OK

Launching R

Run R using the command $TOP_SRCDIR/bin/x64/Rgui.exe. Help > About displays this information for my local build.

Information about my local R build

Article info



Leave a Reply

Your email address will not be published. Required fields are marked *