Build multiarch R (32 bit and 64 bit) on Debian/Ubuntu

[This article was first published on Super Nerdy Cool » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I have the 64 bit version of R compiled from source on my Ubuntu laptop. I recently had a need for R based on 32 bit since a package I needed to compile and use only works in 32 bit. I thought it was readily available on Ubuntu since both 32 bit and 64 bit versions of R are shipped with the Windows and Mac OS X installers. I tried figuring out how to do so using the manual (R 2.13.1), but could not figure it out on my own. I seeked help on R-devel and received some helpful responses.

Here is a quick reminder for myself:

## download R source from tar ball or svn
## working directory has R/trunk/
## run in trunk
./tools/rsync-recommended
sudo apt-get install ia32-libs lib32readline6-dev lib32ncurses5-dev lib32icu-dev gcc-multilib gfortran-multilib ## ubuntu does not have ia32-libs-dev
# cd ../..
# mkdir R32
# cd R32
# ../R/trunk/configure r_arch=i386 CC='gcc -std=gnu99 -m32' CXX='g++ -m32' FC='gfortran -m32' F77='gfortran -m32'
# make -j24 && sudo make install
# cd ..
# mkdir R64
# ../R/trunk/configure r_arch=amd64
# make -j24 && sudo make install
./configure r_arch=i386 CC='gcc -std=gnu99 -m32' CXX='g++ -m32' FC='gfortran -m32' F77='gfortran -m32'
make -j24 && sudo make install
make clean
./configure r_arch=amd64
make -j24 && sudo make install

You can build directly in the R/trunk, but make sure you execute make clean first to clear out any previous builds. Not doing so gave me errors like:

/usr/bin/install: cannot create regular file
`../../include/i386/Rconfig.h': No such file or directory

Now, executing R will give me the 64 bit version of R (whatever was the last build). If I want to specify the arch, I can just issue the commands R --arch i386 or R --arch amd64. When launching R in emacs, do C-u M-x R and type in the --arch argument.

Do a make uninstall to remove R prior to installing a new version of R to the same location.

To leave a comment for the author, please follow the link and comment on their blog: Super Nerdy Cool » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.