---Installing R packages---
If you already have an R package, and just want to install it, use the links below and follow steps 1,7,8 (Linux-Linux) for Linux [.tar] packages, or step 6 (Windows-Windows) for windows [.zip] R packages.---Creating and installing R packages from scratch---
The instructions below come in a few different flavours. Building packages in... | Linux for use in R for Linux | | Linux for use in R for Windows | | Windows for use in R for Windows | | Windows for use in R for Linux | | Mac OS | |
| Sample Windows build output | | Troubleshooting | |
Tip: If, like me, you are constantly changing your code and building different package versions, you can install packages "tidily" by using the install command R CMD INSTALL --with-package-versions -l /home/maman/myrlibrary roots_0.1-1.tar.gz. This will install the package as /myrlibrary/roots_0.1-1, and has the effect that you can load packages by version with e.g. library(roots, version="0.1-1").8. To see if the package works, start R from whichever directory you want, and type library(roots). A sometimes useful addition to the package structure is to add the file zzz.r (above) to your package subdirectory R. This prints a message to tell you when your package has loaded. Then test out your functions, eg. fifthroot(32).
Note: If you do this, then a simple library(roots) command will load the latest package version. However, BEWARE of doing a mixture of installing --with-package-versions and not; if you do, a simple library(roots) command will load the package without a version number.
Tip: You can create a package skeleton in R, by sourcing your functions/code into the workspace and then using the command package.skeleton(name="roots",list=ls()). Then edit the DESCRIPTION file and .Rd files appropriately.4. Open a command prompt (Start->Programs->Accessories->Command Prompt). Change directory to your version of R: (normally eg cd \Program Files\R\rw1090\bin.
Tip: It is worth issuing the command Rcmd check package before building it, especially if your package is large or contains code from various sources, so that any problems in code, examples, help files etc can be located prior to distributing the package. I think this also is responsible for building/updating the html versions of the help files.6. Install the package in R in the usual way: Packages -> Install package(s) from local .zip files, then library(roots). Note that the .zip file will be contained in the R bin location C:\Program Files\R\rw1090\bin.
* checking for working latex ... OK===============================
* using log directory 'C:/removethis/R-2.2.1/bin/roots.Rcheck'
* using R version 2.2.1, 2005-12-20
* checking for file 'roots/DESCRIPTION' ... OK
* this is package 'roots' version '0.1-3'
* checking if this is a source package ... OK
installing R.css in C:/removethis/R-2.2.1/bin/roots.Rcheck
---------- Making package roots ------------
adding build stamp to DESCRIPTION
making DLL ...
making fifrt.d from fifrt.c
gcc -Ic:/removethis/R-2.2.1/include -Wall -O2 -c fifrt.c -o fifrt.o
g77 -O2 -Wall -c fthrt.f -o fthrt.o
ar cr roots.a fifrt.o fthrt.o
ranlib roots.a
windres --include-dir c:/removethis/R-2.2.1/include -i roots_res.rc -o roots_re
s.o
gcc --shared -s -o roots.dll roots.def roots.a roots_res.o -Lc:/removethis/R-
2.2.1/src/gnuwin32 -lg2c -lR
... DLL made
installing DLL
installing R files
installing data files
installing man source files
installing indices
not zipping data
installing help
>>> Building/Updating help pages for package 'roots'
Formats: text html latex example chm
cuberoot text html latex example
fifthroot text html latex example
fourthroot text html latex example
table.of.roots text html latex
Microsoft HTML Help Compiler 4.74.8702
Compiling c:\removethis\rw1090\roots\chm\roots.chm
Compile time: 0 minutes, 0 seconds
5 Topics
16 Local links
0 Internet links
1 Graphic
Created c:\removethis\rw1090\roots\chm\roots.chm, 16,409 bytes
Compression increased file by 4,371 bytes.
adding MD5 sums
* DONE (roots)
* checking package directory ... OK
* checking for portable file names ... OK
* checking DESCRIPTION meta-information ... OK
* checking package dependencies ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking R files for syntax errors ... OK
* checking R files for library.dynam ... OK
* checking S3 generic/method consistency ... OK
* checking replacement functions ... OK
* checking foreign function calls ... OK
* checking Rd files ... OK
* checking for missing documentation entries ... OK
* checking for code/documentation mismatches ... OK
* checking Rd \usage sections ... OK
* checking for CRLF line endings in C/C++/Fortran sources/headers ... OK
* creating roots-Ex.R ... OK
* checking examples ... OK
* creating roots-manual.tex ... OK
* checking roots-manual.tex ... OK
* checking for file 'C:/removethis/rw1090/roots/DESCRIPTION' ... OK===============================
* preparing 'C:/removethis/rw1090/roots':
* checking DESCRIPTION meta-information ... OK
* cleaning src
* removing junk files
* checking for LF line-endings in source files
* checking for empty directories
* building 'roots_0.1-3.tar.gz'
* checking for file 'C:/removethis/rw1090/roots/DESCRIPTION' ... OK
* preparing 'C:/removethis/rw1090/roots':
* checking DESCRIPTION meta-information ... OK
* cleaning src
* removing junk files
* checking for LF line-endings in source files
* checking for empty directories
* building binary distribution
WARNING
* some HTML links may not be found
Using auto-selected zip options ''
---------- Making package roots ------------
adding build stamp to DESCRIPTION
making DLL ...
making fifrt.d from fifrt.c
gcc -Ic:/removethis/R-2.2.1/include -Wall -O2 -c fifrt.c -o fifrt.o
g77 -O2 -Wall -c fthrt.f -o fthrt.o
ar cr roots.a fifrt.o fthrt.o
ranlib roots.a
windres --include-dir c:/removethis/R-2.2.1/include -i roots_res.rc -o roots_re
s.o
gcc --shared -s -o roots.dll roots.def roots.a roots_res.o -Lc:/removethis/R-
2.2.1/src/gnuwin32 -lg2c -lR
... DLL made
installing DLL
installing R files
installing data files
installing man source files
installing indices
not zipping data
installing help
>>> Building/Updating help pages for package 'roots'
Formats: text html latex example chm
cuberoot text html latex example chm
fifthroot text html latex example chm
fourthroot text html latex example chm
table.of.roots text html latex chm
Microsoft HTML Help Compiler 4.74.8702
Compiling c:\TEMP\Rbuild.1320\roots\chm\roots.chm
Compile time: 0 minutes, 0 seconds
5 Topics
16 Local links
0 Internet links
1 Graphic
Created c:\TEMP\Rbuild.1320\roots\chm\roots.chm, 16,405 bytes
Compression increased file by 4,367 bytes.
adding MD5 sums
packaged installation of package 'roots' as roots_0.1-3.zip
* DONE (roots)
preparing package roots for lazy loadingCause: Lazy loading is not working properly (though i am not really sure what that is).
Error in tools:::.read_description(file) :
file '/DESCRIPTION' does not exist
Execution halted
make: *** [lazyload] Error 1
*** Installation of roots failed ***
if($WINDOWS) {add "no-lazy" to the list of known_options (within the parentheses). Then under my $INSTALL_opts (at about line 90), where it says if($WINDOWS) {, add the line
die "Please set TMPDIR to a valid temporary directory\n"
unless (-e ${R::Vars::TMPDIR});
@known_options = ("help|h", ...
* checking for working latex ... Error: environment variable TMPDIR not set (or set to unusable value) and no default availableCause: Well, it tells you: it wants the location of the windows temporary directory, though this should be set up already. (We have encountered this on Windows XP).
Found the following C sources/headers with CRLF line endings: src/fifrt.c ISO C requires LF line endings.Cause: This is a difference between line endings in text files on different OS systems, and this problem occurs when sharing text files across multiple OS. (We encountered this problem when using Windows XP).