Building R packages in Windows


Disclaimer: The instructions below describe what I've been doing to compile an R package for Windows. Check out the files src/gnuwin32/INSTALL and src/gnuwin32/readme.packages in the R source distribution for the official (and recommended) approach. Most importantly, see this page.

Also note: there is an online service (http://win-builder.r-project.org) for building and checking R packages for Windows.

Preparations

  1. Look at the Windows toolset appendix in the R Administration manual.
  2. Go to the webpage cran.us.r-project.org/bin/windows/Rtools
  3. Download and install the Rtools.exe file. This includes:

    1. A bunch of command-line tools
    2. Perl
    3. The MinGW compiler

    When given the option to edit your PATH, take it (see item 5 below).

  4. You may also want:

    1. Microsoft's HTML Help Workshop
    2. MikTeX
  5. Make sure your PATH contains all of the right directories (e.g., that the R bin directory is correct). (When you install Rtools.exe, you're given the option to edit your PATH.)

    1. Go to "Control Panel -> System."
    2. Click on the tab "Advanced" and then on "Environment Variables."
    3. Highlight "Path" at the bottom and click "Edit".
    4. In the character string in "Variable Value", you want c:\Rtools\bin;c:\Rtools\perl\bin;c:\Rtools\MinGW\bin;c:\R\bin and then any other stuff at the end. (Most problems I've experienced have been due to incorrect directories here, or an incorrect order in the directories.)


Building an R package in Windows

With R version 2.14, this is easier than ever before. I'll use, as an example, my own package, qtl.

  1. Go to the directory containing the source package, say c:\MyRpackages (containing the file qtl_1.22-18.tar.gz)
  2. Type R CMD INSTALL --build qtl_1.22-18.tar.gz
  3. A file like qtl_1.22-18.zip should be created.

To build the package for both 32- and 62-bit Windows, you need to

  1. Select to include the 64-bit files when you install R.
  2. Build the package using R CMD INSTALL --build --compile-both qtl_1.22-18.tar.gz


Back to home page

Last modified: Mon Apr 9 10:16:06 2012