Compiling R Package from Source Code

Wenxuan Zhang
2 min readMar 31, 2022

Have you ever run into the following warnings? If yes, you need to compile the R source code to binary (two type of R packages, binary/source).

Then you need to have RTools installed. Select your Rtools based on your R version.

My R version is :3.5.3 thus I choose Rtools35. The Rtools install process is quick & easy. However, to really leverage Rtools, you need to change your system setting in R/Rstudio.

Sys.setenv(PATH = paste("C:/Rtools/mingw_64/bin/", Sys.getenv("PATH"), sep=";"))Sys.setenv(BINPREF = "C:/Rtools/mingw_64/bin/")#The 'C:/Rtools/mingw_64/bin/' is where you can find the gcc program
# It can vary by where you installed your Rtools
#validate whether Rtool were setup correctlySys.which('make')

After setting the profile, you could install those packages that does not have binary version available.

For example, if I wanted to install shiny framework, then I will type


install.packages('shiny',type = 'source',dependency = TRUE)

Hope this works for you!

Ming32 and Mingw64

One new thing that I learned from this process is Mingw32 and Mingw64. Ming.

Mingw is short for Minimalist GNU for Windows. It is an opensource framework to create the create Microsoft windows applications. Though it is called 32, it can run on both 64 bit and 32 bit systems. The Mingw64 was build (2005–2010) based upon Mingw32 to adapt to the introduction of 64 bit CPU in mainstream personal computer.

Per eliahonader’s answer: MinGW (x86_64-w64-mingw32-gcc not found) — Stack Overflow

There are three main versions of the MingW:

1- mingw32-gcc.exe the compiler will build 32-bit applications on 32-bit systems.

2- i686-w64-mingw32-gcc.exe the compiler will build 32-bit applications on 64-bit systems.

3- x86_64-w64-mingw32-gcc.exe the compiler will build 64-bit applications on 64-bit systems

Thus, R version 3.5.3 is a software is a 32 bit applications built on 64 bit systems :). Thus, when setting systems, we should use mingw_64

Sys.setenv(PATH = paste("C:/Rtools/mingw_64/bin/", Sys.getenv("PATH"), sep=";"))Sys.setenv(BINPREF = "C:/Rtools/mingw_64/bin/")

Correct me if anything was wrong :).

Reference

64-bit computing — Wikipedia

Mingw-w64 — Wikipedia

--

--