R CMD BATCH?
This FAQ is for the Windows port of R: it describes features specific to that version. The main R FAQ can be found at
The information here applies only to recent versions of R for Windows,
2.0.0 or later); the current version is often called something like
rw2001 (although not officially).
Go to any CRAN site (see http://cran.r-project.org/mirrors.html
for a list), navigate to the
bin/windows/base directory and
collect the files you need. There are two versions of the distribution
of the current release.
rw2001.exe is about 23Mb. This contains all the components
and allows as complete as installation as you choose.
miniR.exe and seven files
miniR-?.bin. You can put
on one floppy and the remaining
miniR-?.bin on a floppy each.
This is a small installation, containing the text versions of the help
files and the An Introduction to R and Data Import/Export
manuals in PDF. There is no support for
tcltk in this version,
and no documentation for packages
There are also links on that page to the
r-devel releases. These are frequently updated builds of development
versions of R. The
r-patched build includes bug fixes to the
current release, and
r-devel contains changes that will eventually
make it into the next major
You need Windows 95/98/ME/NT4/2000/XP/2003 Server: Windows 3.11+win32s will not work. Your file system must allow long file names (as is likely except perhaps for some network-mounted systems). A full installation takes up about 50Mb of disk space and a minimal one about 15Mb.
If you want to build packages from sources, we recommend that you choose an installation path not containing spaces. (Using a path with spaces in will probably work, but is little-tested.)
To install use
double-click on the icon and follow the instructions. If you installed
R this way you can uninstall it from the Control Panel or Start Menu
(unless you supressed making a group for R).
Choose a working directory for R. If you installed manually, make a
rw2001\bin\Rgui.exe on your desktop or somewhere on
the Start menu file tree. Right-click the shortcut, select
Properties... and change the `Start in' field to your working directory.
You may also want to add command-line arguments at the end of the Target
field (after any final double quote), for example
--max-mem-size=1Gb. You can also set environment variables at the end
of the Target field, for example
The normal way to customize the installation is by selecting components from the wizards shown. However, sysadmins might like to install R from scripts, and the following command-line flags are available for use with either installer.
rw2001.exe, which has components
It is also possible to save the settings used to a file and later reload those settings using
A successful installation has exit code 0: unsuccessful ones may give 1, 2, 3, 4 or 5. See the help for Inno Setup 4 (http://jrsoftware.org/isinfo.php) for details.
Just double-click on the shortcut you prepared at installation.
If you want to set up another project, make a new shortcut or use the existing one and change the `Start in' field of the Properties.
You may if you prefer run R from the command line of any shell you use,
for example an `MS-DOS window' (Windows 9x/ME), a `Command Prompt'
(Windows 2000/XP) or a port of a Unix shell such as
bash. (The command line can be anything you would put in the
Target field of a shortcut, and the starting directory will be the
currect working directory of the shell.)
Normally you can do this from the R group on the Start Menu or from the
Add/Remove Programs in the Control Panel. If it does not appear
there or if you want to remove an old version, run unins000.exe
in the top-level installation directory. (There should be a separate
uninstall item in the R group for each installed version of R.)
Uninstalling R only removes files from the initial installation, not (for example) packages you have installed.
If all else fails, you can just delete the whole directory in which R was installed.
That's a matter of taste. For most people the best thing to do is to
uninstall R (see the previous Q), install the new version, copy any
installed packages to the library folder in the new installation, run
update.packages() in the new R (`Update packages from CRAN' from
the Packages menu, if you prefer) and then delete anything left of the
old installation. Different versions of R are quite deliberately
installed in parallel folders so you can keep old versions around if you
Upgrading from R 1.x.y to R 2.0.0 is special as all the packages need to be reinstalled. Rather than copy them across, make a note of their names and re-install them from CRAN.
Indeed there is. It is set by the command-line flag --max-mem-size (see How do I install R for Windows?) and defaults to the smaller of the amount of physical RAM in the machine and 1Gb. It can be set to any amount over 16M. (R will not run in less.) Be aware though that Windows has (in most versions) a maximum amount of user virtual memory of 2Gb, and parts of this can be reserved by processes but not used. The version of the memory manager used from R 1.9.0 allocates large objects in their own memory areas and so is better able to make use of fragmented virtual memory than that used previously.
?memory.size for information about memory
usage. The limit can be raised by calling
memory.limit within a
running R session.
R can be compiled to use a different memory manager which might be better at using large amounts of memory, but is substantially slower (making R several times slower on some tasks).
If you are running a version of Windows which supports more than 2Gb per process, you can let the R executables use it by marking their headers suitably. If you have Visual Studio use
editbin /LARGEADDRESSAWARE \path\to\rwxxxx\bin\Rgui.exe editbin /LARGEADDRESSAWARE \path\to\rwxxxx\bin\Rterm.exe
and check this by
dumpbin /headers \path\to\rwxxxx\bin\Rgui.exe dumpbin /headers \path\to\rwxxxx\bin\Rterm.exe
You should see a line like
Application can handle large (>2GB) addresses
Create a separate shortcut for each project: see Q2.4. All the paths to files used by R are relative to the starting directory, so setting the `Start in' field automatically helps separate projects.
Alternatively, start R by double-clicking on a saved .RData file in the directory for the project you want to use, or drag-and-drop a file with extension .RData onto an R shortcut. In either case, the working directory will be set to that containing the file.
It depends what you want to print.
dev.printwith suitable arguments (see its help page: most likely
File | Print. (This will print the selection if there is one, otherwise the whole console or pager contents.)
RHOME\bin\helpPRINT.batand have LaTeX installed you can print help files by
R CMD BATCH?
R CMD BATCH --help or
?BATCH for full details.
You can set also up a batch file using
Rterm.exe. A sample
batch file might contain (as one line)
path_to_R\bin\Rterm.exe --no-restore --no-save < %1 > %1.out 2>&1
The purpose of
2>&1 is to redirect warnings and errors to the
same file as normal output, and users of Windows 95/98/ME's default
command.com `shell' will need to omit it. (That program has no
means to redirect stderr, and
Rterm.exe sends warnings and
errors to the normal output file on such systems.)
Yes. Recent versions of ESS (e.g. 5.2.0) come with support for this
version of R, and there is support for interrupting the R process from
For help with ESS, please send email to ESSemail@example.com, not the R mailing lists.
Several places in the documentation use these terms.
The working directory is the directory from which
Rterm was launched, unless a shortcut was used when it is given
by the `Start in' field of the shortcut's properties. You can find this
from R code by the call
The home directory is set as follows: If environment variable
R_USER is set, its value is used. Otherwise if environment
variable HOME is set, its value is used. After those two
user-controllable settings, R tries to find system-defined home
directories. It first tries to use the Windows "personal" directory
C:\Documents and Settings\username\My Documents in
Windows XP). If that fails, if both environment variables
HOMEDRIVE and HOMEPATH are set (and they normally are under
Windows NT/2000/XP), the value is
If all of these fail, the current working directory is used.
You can find this from R code by
Environment variables can be set for
Rterm.exe in three different ways.
RGuiyou could have
path_to_R\bin\Rgui.exe HOME=p:/ R_LIBS=p:/myRlib
If you have permission to do so, you can also create an environment file etc\Renviron.site and set environmental variables in that file in the same way. This is useful for variables which should be set for all users and all usages of this R installation. (Their values can be overridden in a .Renviron or on the command line.)
?Startup for more details of environment files.
Rterm. Under Windows NT/2000/XP you can use the control panel or the properties of `My Computer'. Under Windows ME you can use the System Configuration Utility (under Programs, Accessories, System Tools on the Start menu). You may have to log out or reboot for such changes to take effect.
The order of precedence for environmental variables is the order in which these options are listed, that is the command line then .Renviron then the inherited environment.
How did you specify it? Backslashes have to be doubled in R character
strings, so for example one needs
"d:\\rw2001\\library\\xgobi\\scripts\\xgobi.bat". You can make
life easier for yourself by using forward slashes as path separators:
they do work under Windows.
Another possible source of grief is spaces in folder names. We have
tried to make R work on paths with spaces in, but many people writing
packages for Unix do not bother. So it is worth trying the alternative
short name (something like
PROGRA~1; you can get it as the
`MS-DOS name' from the Properties of the file on most versions of
Windows, and from
dir /X in a
Command Prompt window on
The installers set some entries to allow uninstallation. In addition
(by default, but this can be de-selected) they set a Registry key
LOCAL_MACHINE\Software\R-core\R giving the version and install
path. Again, this is not used by R itself, but it will be used by the
DCOM interface (http://cran.r-project.org/other-software.html).
Finally, a file association for extension
.RData is set in the
You can add the Registry entries by running
RSetReg.exe in the
bin folder, and remove them by running this with argument
/U. Note that the settings are all per machine and not per user,
and that this neither sets up nor removes the file associations.
There is a (D)COM server written by Thomas Baier available on CRAN
(http://cran.r-project.org/other-software.html) which works with
Rproxy.dll (in the R distribution) and
R.dll to support
transfer of data to and from R and remote execution of R commands, as
well as embedding of an R graphics window. An R-Excel interface making
use of the DCOM server is included in the distribution.
Another (D)COM server is available from http://www.omegahat.org/,
which allows R objects to be exported as COM values. That site also
SWinTypeLibs which allow R
to act as a (D)COM client.
update.packages and the menu items on the Packages menu.
We have had several reports of this, although they do work for us on all of our machines. There are two known possible fixes.
(a) Use the alternative
internet2.dll by starting R with the flag
--internet2 (see How do I install R for Windows?) which uses
the Internet Explorer internals (and so needs Internet Explorer 4 or
later installed). Note that this does not work with proxies that need
(b) A proxy needs to be set up: see
?download.file. Here are two
versions of an example (a real one, but from a machine that is only
available locally) of a command-line in a short cut:
/R/rw2001/bin/RGui.exe http_proxy=http://user:pass@gannet:80/ /R/rw2001/bin/RGui.exe http_proxy=http://gannet/ http_proxy_user=ask
The second version will prompt the user for the proxy username and password when HTTP downloads are first used.
This used to happen occasionally, and all the occurrences we have solved have been traced to faulty versions of msvcrt.dll. We have installed a workaround that seems to avoid this. A few other people have discovered this was caused by desktop switcher and keyboard macro programs, for example `Macro Magic' and `JS Pager'.
If it still happens, try extracting the msvcrt.dll to be found in
the self-extracting archive
ftp://ftp.microsoft.com/softlib/mslfiles/msvcrt.exe and put it in
rw2001\bin directory. Removing msvcrt.dll from that
directory reverts to the standard behaviour. It seems that on some
versions of Windows (but not 2000/XP) you also need to put the
rw2001\bin directory early in your path.
This fix has solved other problems too, for example incorrect results in the date-time functions. However, you are probably better off re-installing Windows.
Some users have found that
Rgui.exe fails to start, exiting with
a “Floating- point invalid operation” or other low level error. This
error may also happen in the middle of a session. In some cases where
we have tracked this down, it was due to bugs in the video driver on the
system in question: it makes changes to the floating point control word
which are incompatible with R. (Good practice would restore the control
word to the state it was in when the driver code was called.) For
example, one user reported that the virtual screen manager JSP2 caused
These errors are essentially impossible for us to fix or work around. The only solution we know of is for the user to replace the buggy driver that is causing the error.
Yes, but you will need a lot of tools to do so, unless the author or the
maintainers of the
bin/windows/contrib section on CRAN have been
kind enough to provide a pre-compiled version for Windows as a
You can install pre-compiled packages either from CRAN or from a local
.zip file by using
install.packages: see its help page.
There are menu items on the
Packages menu to provide a
point-and-click interface to package installation. The packages for
each minor (2.x) version will be stored in a separate area, so for R
2.0.? the files are in
bin/windows/contrib/2.0. You can try
those compiled for earlier versions, at your own risk.
Note that the pre-compiled versions on CRAN are unsupported: see http://cran.r-project.org/bin/windows/contrib/ReadMe, which also gives the locations of a few other precompiled packages.
If there is not a pre-compiled version or that is not up-to-date or
you prefer compiling from source, make sure you installed the
necessary files from
rw2001.exe. Then read the file
README.packages. You will need to collect and install several
tools to use this: you can download them via the portal at
http://www.murdoch-sutherland.com/Rtools/. Once you have done so,
R CMD INSTALL pkgname. To check the package (including
running all the examples on its help pages and in its test suite, if
R CMD check pkgname: see the `Writing R
Note that this is rather tricky; please do ensure that you have followed the instructions exactly. At least 90% of the questions asked are because people have not done so.
You can install packages anywhere and use the environment variable R_LIBS (see How do I set environment variables?) to point to the library location(s).
Suppose your packages are installed in
p:\myRlib. Then you can
set the environment variable R_LIBS to p:\myRlib
OR use a package by, e.g.
To update the HTML indices after you have installed a pre-compiled package, run at the R prompt.
This is done automatically when installing from the Packages menu or
install.packages(), and when
help.start is run,
provided you have write permission in rw2001. If you do not
have sufficient permission, you will get warnings and the packages you
install will not appear in the list of packages or the search system.
The following conditions need to hold for functions in a package you installed.
If the help search system does not work at all, this probably indicates that Java support is either not installed or not enabled in your browser. The search page contains a link to the appropriate section in the R Installation and Administration manual.
Is the package compiled for this version of R? Many of the packages need to be compiled for a fairly recent version.
You can tell the version the package was compiled for by looking at the
Built: line in its DESCRIPTION file or at the
Version tab of its DLL in the libs directory.
(Right-click on the DLL in Windows Explorer and select
tab of the
Properties, or use the
tcltk to work (try
library(tcltk)) you need to have Tcl
installed. This is an optional part of the installation by
rw2001.exe, although it is selected by default.
If the message is
Tcl/Tk support files were not installed
the optional files were not installed, and you need to go back to the
installer and install them. (Note: package
tcltk is not part of
Alternatively, if you have the environment variable
to a non-empty value, it is assumed that you want to use a different
Tcl/Tk 8.4.x installation, and that this is set up correctly (with the
DLLs in your path and
TCL_LIBRARY set). In that case you do not
need the Tcl/Tk support files installed (but they can be). Note that
you do need 8.4.x and not 8.3.x. (If you build R from the sources
yourself you can configure it to use 8.3.x.)
They may well not work between packages installed in different libraries. This is solved under Unix using symbolic links which Windows does not implement.
You may not be able to update a package which is in use: Windows `locks'
the package's DLL when it is loaded. So use
(or the menu equivalent) in a new session.
If you put
library(foo) in your .Rprofile you will need to
start R with --vanilla to be able to update package
If you set
R_DEFAULT_PACKAGES to include
foo, you will
need to unset it temporarily.
Rgui.exeand <Ctrl-break> or <Ctrl-C> in
Rterm.exe: <Ctrl-C> is used for copying in the GUI version.
Rgui.exe, the menu item `Help | Console' will give details. For
Rterm.exesee file README.rterm.
help.start()does not automatically send help requests to the browser: use
options(htmlhelp=TRUE)to turn this on.
source()) can be specified with either "/" or "\\".
system()is slightly different: see its help page and that of
You have read the
README.rw2001? There are file menus on the R console,
pager and graphics windows. You can source and save from those menus,
and copy the graphics to
metafile. There are right-click
menus giving shortcuts to menu items, and optionally toolbars with
buttons giving shortcuts to frequent operations.
If you resize the R console the
options(width=) is automatically
set to the console width (unless disabled in the configuration file).
The graphics has a history mechanism. As
`The History menu allows the recording of plots. When plots have been recorded they can be reviewed by <PgUp> and <PgDn>, saved and replaced. Recording can be turned on automatically (the Recording item on the list) or individual plots can be added (Add or the <INS> key). The whole plot history can be saved to or retrieved from an R variable in the global environment. The format of recorded plots may change between R versions. Recorded plots should not be used as a permanent storage format for R plots.The R console and graphics windows have configuration files stored in the RHOME\etc directory called Rconsole and Rdevga; you can keep personal copies in your HOME directory. They contain comments which should suffice for you to edit them to your preferences. For more details see
There is only one graphics history shared by all the windows devices.'
?Rconsole. There is a Preferences editor invoked from the
Editmenu which can be used to edit the file Rconsole.
The graphics system asks Windows for the number of pixels per inch in
the X and Y directions, and uses that to size graphics (which in R are
in units of inches). Sometimes the answer is a complete invention, and
in any case Windows will not know exactly how the horizontal and
vertical size have been set on a CRT. You can specify correct values
either in the call to
windows or as options: see
(Typically these are of the order of 80.)
On one of our systems, the screen height is reported as 240mm, and the width as 300mm in 1280 x 1024 mode and 320mm in 1280 x 960 and 1600 x 1200 modes. In fact it is a 21" monitor and 400mm x 300mm!
You may want to do this from within a function, for example when calling identify or readline. Use the function bringToTop(). With its default argument it brings the active graphics window to the top and gives it focus. With argument -1 it brings the console to the top and gives it focus.
This works for Rgui.exe in MDI and SDI modes, and can be used for graphics windows from Rterm.exe (although Windows may not always act on it).
Have you changed the working directory?: see Q5.2.
Use the `File | Change Dir...' menu item to select a new working directory: this defaults to the last directory you loaded a file from. The workspace is saved in the working directory. You can also save a snapshot of the workspace from the `Save Workspace...' menu item.
From the command line you can change the working directory by the
setwd: see its help page.
Yes. All ports of R use the same format for workspaces, so they are interchangeable (for the same 2.x.? version of R, at least).
for example, in the console and to annotate graphs. Similar comments apply to any non-Western European language.
We believe this is possible by setting suitable fonts in the Rconsole and Rdevga configuration files (see Q4.2 and the next Q). You can specify additional fonts in Rdevga, and use them by
par(font=, font.lab=, font.main=, font.sub=)
Nineteen fonts are specified (as 1 to 19) by default: you can add to these (up to 13 more) or replace them.
In addition, the Hershey vector fonts (see
demo(Japanese)) can be used on any graphics
device to display Japanese characters.
To use non-Latin1 characters in the
postscript graphics device,
see its help page.
You need to specify a font in Rconsole (see Q4.2) that supports the
encoding in use, in Western European languages Latin1. The default
Courier New, does on our systems, as does
This may be a problem in other locales, especially for non-Western
Support for these characters within
Rterm depends on the
environment (the terminal window and shell, including locale settings)
within which it is run as well as the font used by the terminal window.
If you are using a non-Latin1 language, you do need to ensure that the
fonts you selected support the language. For example, it was found by
one Czech user (under Windows 98) that he had to select
Roman CE or
Courier New) to get certain
Czech characters displayed correctly.
This is deliberate: the console output is buffered and re-written in chunks to be faster and less distracting. You can turn buffering off or on from the `Misc' menu or the right-click menu: <Ctrl-W> toggles the setting.
If you are sourcing R code or writing from a function, there is another
option. A call to the R function
flush.console() will write out
the buffer and so update the console.
They only seem to be truncated: that $ at the end indicates you can scroll the window to see the rest of the line. Use the horizontal scrollbar or the <CTRL + left/right arrow> keys to scroll horizontally. (The <left/right arrow> keys work in the pager too.)
Get the R sources. Suppose you want to compile R-2.0.1. Start in a directory whose path does not contain spaces, and run
tar zxvf R-2.0.1.tgz cd R-2.0.1 cd src\gnuwin32
Now read the INSTALL file and set up all the tools needed. Then
you can just use
make all bitmapdll recommended vignettes, sit
back and wait. (A complete build takes about 20 minutes on a 2.6GHz P4
with a fast local disc.)
You may need to compile under a case-honouring file system: we found
samba-mounted file system (which maps all file names to lower
case) did not work.
Fast BLAS (Basic Linear Algebra Subprograms,
http://www.netlib.org/blas/faq.html) routines are used to speed
up numerical linear algebra. There is support in the R sources for the
`tuned' BLAS called ATLAS (http://math-atlas.sourceforge.net).
The savings can be appreciable: on a 2.6GHz P4 and a 1000 x 1000 matrix
svd took 16.2 sec with the standard BLAS and 7.8 sec with ATLAS.
Because ATLAS is tuned to a particular chip we can't use it generally:
the optimal routines for a P4 or an Athlon XP are quite different and
neither will not run at all on a PII.
BLAS support is supplied by the single DLL R_HOME\bin\Rblas.dll, and you can add a fast BLAS just by replacing that. Replacements for some of the more common chips are available on CRAN in directory bin/windows/contrib/ATLAS.
If you are building R from source, in the file MkRules there
USE_ATLAS = YES and
ATLAS_PATH to where the ATLAS
libraries are located. You will need to make the libraries yourself:
none of the binaries we have seen are compiled for the correct
Even faster hand-coded routines are available as DLLs from Dr Kazushige
Goto for certain CPUs (Pentium III and 4 and Opteron). He does not
allow redistribution: they are currently available via
http://www.cs.utexas.edu/users/kgoto/signup_first.html and there
is support in the R sources to build R_HOME\bin\Rblas.dll to link
to one of his DLLs. On the
svd problem they took 6.8 sec.
We strongly encourage you to do this via building an R package:
see the `Writing R Extensions' manual. In any event you should
install the parts of the R system for building R packages (in
rw2001.exe), and get and install the tools (including Perl) and
compilers mentioned in the file README.packages contained
therein. Then you can use
...\bin\R CMD SHLIB foo.c bar.f
...\bin\R CMD SHLIB --help for
further options, or see
If you want to use Visual C++, Borland C++ or other compilers, see the appropriate section in README.packages.
You will need a suitable version of
gdb: we normally use that
from the Cygwin distribution. Debugging under Windows is often a
fraught process, and sometimes does not work at all. If all you need is
a just-in-time debugger to catch crashes, consider
Dr. Mingw from the
mingw-utils bundle on
http://www.mingw.org (see also
That will be able to pinpoint the error, most effectively if you build a
version of R with debugging information as described below.
First, build a version of the R system with debugging information by
make clean make DEBUG=T
and make a debug version of your package by either
make pkgclean-mypkg make DEBUG=T pkg-mypkg
Rcmd install -c mypkg set DEBUG=T Rcmd install mypkg
Then you can debug by
gdbwill only be able to find the source code if we run in the location where the source was compiled (
rw2001/src/gnuwin32for the main system,
rw2001/src/library/mypkg/srcfor a package), unless told otherwise by the
directorycommand. It is most convenient to set a list of code locations via
directorycommands in the file .gdbinit in the directory from which
gdb ../../../../bin/Rgui.exe (gdb) break WinMain (gdb) run [ stops with R.dll loaded ] (gdb) break R_ReadConsole (gdb) continue [ stops with console running ] (gdb) continue Rconsole> library(stats) (gdb) break tukeyline (gdb) clear R_ReadConsole (gdb) continue
Alternatively, in Rgui you can use the `Misc|Break to debugger' menu item
after your DLL is loaded. The C function call
will do the same thing.
gdb. It does often work with the
gdbcan be used. We have successfully used the
gdb(see http://sources.redhat.com/insight/), and Borland's debugger with a DLL compiled in a Borland compiler.
You need to do two things:
(a) Write a wrapper to export the symbols you want to call from R as
(b) Include the C++ libraries in the link to make the DLL. Suppose
X.cc contains your C++ code, and X_main.cc is the wrapper,
as in the example in `Writing R Extensions'. Then build the DLL by
...\bin\R CMD SHLIB X.cc X_main.cc
or (VC++, which requires extension
cl /MT /c X.cpp X_main.cpp link /dll /out:X.dll /export:X_main X.obj X_main.obj
or (Borland C++, which also requires extension
bcc32 -u- -WDE X.cpp X_main.cpp
and call the entry point(s) in
X_R, such as
Construction of static variables will occur when the DLL is loaded, and
destruction when the DLL is unloaded, usually when R terminates.
Note that you will not see the messages from this example in the GUI console: see the next section.
This example used to be in package
cxx_0.0-x.tar.gz in the
src/contrib/Devel section on CRAN, and could be compiled as a
package in the usual way on Windows.
Rgui.exe console is a Windows application: writing to
stderr will not produce output in the
console. (This will work with
REprintf instead. These are declared in header file
Note that output from the console is delayed (see The output to the console seems to be delayed), so that you will not normally see any output before returning to the R prompt.
Writing to Fortran output writes to a file, not the
Use one of the subroutines
documented in the `Writing R Extensions' manual.
Note that output from the console is delayed (see The output to the console seems to be delayed), so that you will not normally see any
output before returning to the R prompt even when using the
The console, pagers and graphics window all run in the same thread
as the R engine. To allow the console etc to respond to Windows events,
R_ProcessEvents() periodically from your compiled code.
If you want output to be updated on the console, call
R_FlushConsole() and then