Buildung R binary packages for Windows with WINE under GNU/Linux

Building Windows binaries of R packages may be tricky. A convenient method is using Uwe Ligges' build service win-builder where you can upload an R source package via FTP, wait for a while and then download the Windows binary from a temporary FTP directory (the link is provided in an email sent to the address specified in the Maintainer field in the DESCRIPTION file of the package). If your package doesn't contain compiled C/C++/Fortran (i.e. only R) code, then you can install the source package (i.e. *.tar.gz file) with install.packages(..., type = "source"). However, you might still need to produce a Windows binary (i.e. *.zip file) in such cases. And maybe you'd like to do that on a GNU/Linux machine. Then then following short tutorial is for you.

First, install the Windows emulator WINE. The following works on openSUSE 11.4 (but can of course be adapted to the distribution of your choice):

sudo zypper install wine

Then, download a Windows version of R and install it with WINE (follow the instructions in the graphical installer):

curl http://cran.r-project.org/bin/windows/base/R-2.14.0-win.exe > \
     R-2.14.0-win.exe
wine R-2.14.0-win.exe

A further prerequisite is a ZIP executable for Windows, e.g. Info-ZIP:

curl ftp://ftp.info-zip.org/pub/infozip/win32/zip300xn.zip > \
     zip300xn.zip
unzip zip300xn.zip -d ~/.wine/drive_c/Program\ Files/infozip/

Add the R.exe and zip.exe executables to the Windows (or rather WINE) PATH environment variable for convenience. Open the WINE registry editor and navigate to My Computer > HKEY_CURRENT_USER > Environment. There, create a new string PATH with value C:\Program Files\R\R-2.14.0\bin\i386;C:\Program Files\infozip:

wine regedit

You can check whether PATH is set correctly with the following (just type PATH and hit enter after the WINE terminal has opened):

wine cmd

Now you're ready to build Windows binaries of R packages under GNU/Linux (in case there's no C/C++/Fortran code that needs to be compiled - that would require the setup of an R/Windows development environment, which I haven't tested yet, but see this discussion).
To illustrate, I use Hadley Wickham's extremely useful R package stringr. First, I'll demonstrate how to build the Windows binary with the win-builder. Then, building with WINE is shown.

Get the package source code:

git clone https://github.com/hadley/stringr.git

Replace the Maintainer field in the DESCRIPTION file because otherwise Mr. Wickham will receive unrequested email from the win-builder build service:

sed -e 's/Maintainer: Hadley Wickham <h.wickham@gmail.com>/\
Maintainer: You <you@example.org>/g' \
stringr/DESCRIPTION > stringr/DESCRIPTION.new
mv stringr/DESCRIPTION.new stringr/DESCRIPTION

Next, build the source package (*.tar.gz) and upload it to win-builder. One could do that manually. A nicer way is using Hadley Wickham's devtools package:

R --slave <<EOF
library(devtools)
build_win("stringr")
install.packages("plyr")
EOF

Note that the dependency plyr was also installed in the R call above. After a while, check your email for a message by Uwe Ligges (CRAN maintainer for Windows binary packages) and download the Windows binary built by win-builder (note that the follwing URLs are only temporary and probably don't exist anymore):

mkdir stringr_winbuilder
curl http://win-builder.r-project.org/c0Arnirh26kP/00check.log > \
     stringr_winbuilder/00check.log
curl http://win-builder.r-project.org/c0Arnirh26kP/00install.out > \
     stringr_winbuilder/00install.out
curl http://win-builder.r-project.org/c0Arnirh26kP/stringr_0.6.zip > \
     stringr_winbuilder/stringr_0.6.zip

The procedure using win-builder is convenient, however it involves a number of manual steps and is quite time consuming. Let's see how the same can be achieved with WINE.

Install dependencies for package stringr with the Windows version of R:

wine R --slave <<EOF
install.packages("plyr")
EOF

Build the binary package with the Windows version of R:

wine R CMD INSTALL --build stringr_0.6.tar.gz

It's that simple once R and the ZIP utility for Windows are set up with WINE.

To finish off, one could compare the Windows binaries produced with win-builder and with WINE:

unzip stringr_0.6.zip -d stringr_zip_wine_extracted
unzip stringr_winbuilder/stringr_0.6.zip \
      -d stringr_zip_win-builder_extracted
diff -r stringr_zip_wine_extracted/ stringr_zip_win-builder_extracted/
This entry was posted in R. Bookmark the permalink.

Leave a reply