[R] The steps of building library in R 2.1.1

J. Hosking jh910 at juno.com
Sun Jul 24 23:02:32 CEST 2005

Duncan Murdoch wrote:

> Could you point out the specific bits that are missing from the R-Admin 
> manual (and perhaps supply them)?  It won't get better unless someone 
> improves it.

R-admin is fine.  The problem is in "Writing R extensions", which
would benefit from containing an explicit recipe for constructing an R
package, and in particular for constructing an R package under Windows
in both source and binary versions.  Several such recipes have been
posted to the internet or R-help.  The one that I have found to be the
most useful was posted to R-help by Gabor Grothendieck on 2 March 2005.
I am appending it below, with some trivial modifications of my own.
I think it would be very useful if this information were included in
the R-exts manual, perhaps at the end of the "Creating R packages"

J. R. M. Hosking

Making a package under Windows

Make sure that:

- you have read:
    "Writing R Extensions" manual

- you have downloaded and installed the tools from

- you have installed LaTeX (fptex or MiKTeX), perl, the Microsoft help
   compiler, and (if the package contains C or Fortran source code) the
   MinGW compilers, as described at 
     (MiKTeX requires some additional setup, described at

- your path contains the tools, htmlhelp, and the bin directories for R,
   LaTeX, Perl, and (if the package contains C or Fortran source code
   to be compiled with MinGW) MinGW.  The tools directory should be the
   first item in the path.

Assuming that the R installation is in \Program Files\R\rw....

1. Assuming your source package tree is in \Rpkgs\mypackage
    then at a Windows command prompt:

         cd \Rpkgs
         Rcmd install mypackage

    which will install it to \Program Files\R\rw....\library\mypackage.
    Or if you want to install it to a separate library:

         cd \Rpkgs
         md library
         Rcmd install -l library mypackage

2. Now in R:

         ... test it out ...

    or if you installed it to a separate library:

         library(mypackage, lib.loc = "/Rpkgs/library")

3. Once it seems reasonably OK, see whether it passes Rcmd check:

         cd \Rpkgs
         Rcmd check mypackage

    and fix it up until it does.

4. Now create versions for Unix and Windows that you can distribute:

         cd \Rpkgs
         Rcmd build mypackage
         Rcmd build mypackage --binary

More information about the R-help mailing list