R
BATCH
?
rw1023\library
directory.This FAQ is for the Windows port of R: it describes features specific to that version. The main R FAQ can be found at
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html.
The information here applies only to recent versions of R for
Windows, (rw1020
or later); the current version is
often called something like rw1023
(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. You will need at least the files
rw1023b1.zip rw1023b2.zip rw1023h.zip (text help) or rw1023ch.zip (Compiled HTML help)
and you may want rw1023wh.zip
(the Windows help
files) or rw1023w.zip
(the HTML format help files),
rw1023l.zip
(the LaTeX format help files, used for
offline printing), or rw1023d?.zip
(the draft manuals,
in PDF).
Optionally, you can download the installer,
rwinst.exe
.
Alternatively, two installers based on Inno Setup are available.
One, SetupR.exe
, is about 10Mb and gives a complete
installation. The other, miniR.exe
, is a small
installation and comes in five files which fit onto four floppy
discs.
First, you need Windows 95/98/ME/NT4/2000: 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).
The simplest way is to use SetupR.exe
or
miniR.exe
. Just 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).
The next-simplest way is to run the installer (double-click on
the icon for rwinst.exe
and navigate its wizard-like
pages). Alternatively, choose a location and unzip the zip files
(with a tool that preserves long file names and the directory
structure: we recommend the INFO-ZIP project's unzip
).
All the files will unpack into a directory rw1023
.
Choose a working directory for R. Unless you used
SetupR.exe
or miniR.exe
(which did this for
you), make a shortcut to rw1023\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, for example --sdi
--max-mem-size=40M
. You can also set environment variables
at the end of the Target field, for example
R_LIBS=e:/R/library
.
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.
Indeed there is. It is set by the command-line flag
--max-mem-size
and defaults to the smaller of the amount of
physical RAM in the machine and 256Mb. It can be set to any amount
over 10M. 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. R itself reserves 256Mb on
startup. Because of the way the memory manager works, it is
possible that there will be free memory but R will not be able to
reserve it.
Use ?Memory
and ?memory.size
for
information about memory usage.
R can be compiled to use a different memory manager which may be better at using large amounts of memory, but is substantially slower (making R several times slower on some tasks).
Create a separate shortcut for each project: see Q2.3. All the paths to files used by R are relative to the starting directory, so setting the `Start in' field automatically helps separate projects.
It depends what you want to print.
dev.print()
.File |
Print
. (This will print the selection if there is one,
otherwise the whole console or pager contents.)RHOME\bin\helpPRINT.bat
and
have latex installed you can print help files by
help(fn_name, offline=TRUE)
.R BATCH
?Yes, if you have Perl and the files for making source packages
(from rw1023sp.zip
) installed. The Windows analogue is
Rcmd BATCH
: use Rcmd BATCH --help
for
full details.
Otherwise you can set 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
Yes. The latest versions of ESS (e.g. 5.1.18) come with support
for this version of R, and there is support for interrupting the R
process from ESS (by C-c C-c
).
For help with ESS, please send email to ESS-help@stat.ethz.ch, not the R mailing lists.
Several places in the documentation use these terms.
The working directory is the directory from which
Rgui
or 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
getwd()
.
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.
Otherwise if environment variables HOMEDRIVE
and
HOMEPATH
are set, the value is
${HOMEDRIVE}${HOMEPATH}
.
If all of these fail, the current working directory is used.
You can find this from R code by
Sys.getenv("R_USER")
.
How did you specify it? Backslashes have to be doubled in R
character strings, so for example one needs
"d:\\rw1021\\library\\xgobi\\scripts\\xgobi.bat"
. 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 lots of
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 on most versions of Windows).
Not itself. The Inno Setup-based installers set some entries to
allow uninstallation. In addition those installers and (by default,
but it can be unchecked) rwinst.exe
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).
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.
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 has been kind enough to provide a pre-compiled
version for Windows as a .zip
file.
You can install pre-compiled packages either from CRAN or from a
local .zip
file by using
install.packages
: see its help page.
Note that the pre-compiled versions on CRAN are unsupported: see
<http://cran.r-project.org/bin/windows/contrib/ReadMe
>
If there is not a pre-compiled version or that is not up-to-date
or you prefer compiling from source, get rw1023.zip
from the distribution (see Q1.1) and unpack it in
rw1023
. Then read the readme.packages
. You will
need to collect and install several tools to use this. Once you
have done so, just run Rcmd INSTALL pkgname
. To check
the package (run all the examples on its help pages and in its test
suite, if any) use Rcmd check pkgname
: see the
`Writing R Extensions' manual.
rw1023\library
directory.You can install packages anywhere and use the environment
variable R_LIBS
to point to the library location(s).
You can also set the R variable .lib.loc
in your
.Rprofile
or when running R.
Suppose your packages are installed in p:\mylibs
.
Then you can EITHER
set the environment variable R_LIBS to p:\mylibs
OR put in the .Rprofile
in the working directory or
your home directory
.lib.loc <- c("p:/mylibs", .Library)
OR use a package by, e.g.
library(MASS, lib.loc="p:/mylibs")
How you set an environment variable is system specific: in
Windows 9x you can set them in autoexec.bat or in an MS-DOS window
from which you launch Rgui
/ Rterm
. Under
Windows NT/2000 you can use the control panel or the properties of
`My Computer'. Under Windows Me you need to use the System
Configuration Utility (under Programs, Accessories, System Tools on
the Start menu). You can also set them on the command line, for
example in the shortcut you could have
path_to_R\bin\Rgui.exe R_LIBS=e:/R/library
and you can set variables in a file .Renviron
in
the working directory or your home directory, for example
R_LIBS=e:/R/library
The order of precedence is the command line then
.Renviron
then the inherited environment.
HTML help only works for packages installed in
rw1023\library
.
To update the HTML help files after you have installed a pre-compiled package, run at the R prompt.
> link.html.help()
The following conditions need to hold for functions in a package you installed.
rw1023\library
.CONTENTS
file in its
top-level directory.If those all hold true, this works for us.
Is the package compiled for this version of R? Many of the
packages need to be compiled for a fairly recent version, and in
particular a substantial minority need to be re-compiled for
rw1020
and later.
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 (if it has one)
in the libs
directory. (Right-click on the DLL in
Windows Explorer, and select Properties
or use the
DLL.version
function inside R.) If there is no
Built:
line or version tab, the package was compiled too
long ago.
For package tcltk
to work (try
demo(tkdensity)
or demo(tkttest)
) you need to
have Tcl installed. Download tcl832.exe
(or use
tcl831.exe
if you already have it) from
<dev.scriptics.com
> and install it. (That will
put the bin
directory containing the Tcl and Tk DLLs
in your path). You then need to set the environment variable
TCL_LIBRARY
, to something like c:/Program
Files/Tcl/lib/tcl8.3
. (The startup code for the package will
warn you if this is unset, and Q3.2 explains how to set them. NB:
do not quote the path, even if as here it contains spaces.)
Unfortunately, hyperlinks in compiled HTML files used from R are
interpreted relative to the current working directory of the R
process, not relative to the pkg.chm
file. This was
not discovered until rw1021
, so only files made since
that version are working correctly. Remake the package under
rw1021
or later to cure this.
Rgui.exe
and <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.help.start()
does not automatically send
help requests to the browser: use options(htmlhelp=T)
to turn this on.source()
) can be specified
with either "/" or "\\".system()
is slightly different: see its help page
and that of shell()
.You have read the README
? 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 png
,
jpeg
, bmp
, postscript
or
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 README says:
`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.There is only one graphics history shared by all the windows devices.'
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 ?Rconsole
. There is a Preferences
editor invoked from the Edit
menu 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 ?windows
. (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!
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.
Yes. The converse (saving on Windows, loading on Unix) also works on almost all Unix systems, and workspaces can be interchanged with the Macintosh port too.
for example, in the console and to annotate graphs.
We believe this is possible by setting suitable fonts in the Rconsole and Rdevga configuration files (see Q4.2). 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.
You need to specify a font in Rconsole (see Q4.2) that supports
latin1 encoding. The default, Courier New
, does on our
systems, as does FixedSys
. This may be a problem in
other locales, especially for non-Western European languages.
This is deliberate: the console output is buffered and re-written in chunks to be 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 message. Use the horizontal scrollbar or the <CTRL+arrow> keys to scroll horizontally.
Get the R sources. Suppose you want to compile R-1.2.2.
tar zxvf R-1.2.2.tgz cd R-1.2.2 cd src\gnuwin32
Now read the INSTALL
file and set up all the tools
needed. Then you can just use make
, sit back and wait.
(A complete build takes about 15 minutes on a 300MHz PII with a
fast local disc.)
You may need to compile under a case-honouring file system: we
found that a samba
-mounted file system (which maps all
file names to lower case) did not work.
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 rw1023sp.zip
, and get and install the
tools (including Perl) and compilers mentioned in the file
readme.packages
there. Then you can use
...\bin\Rcmd SHLIB foo.c bar.c
to make foo.dll
. Use ...\bin\Rcmd SHLIB
--help
for further options, or see ?SHLIB
.
If you want to use Visual C++, Borland C++ or other compilers,
see the appropriate section in readme.packages
.
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
make pkgclean-mypkg make DEBUG=T pkg-mypkg
Then you can debug by
gdb /path/to/rw1023/bin/Rgui.exe
However, note
rw1023/src/gnuwin32
for the main system,
rw1023/src/library/mypkg/src
for a package), unless told
otherwise by the directory
command. It is most
convenient to set a list of code locations via
directory
commands in the file .gdbinit
in the
directory from which gdb
is run.
tukeyline
in package eda
might be
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(eda) (gdb) break tukeyline (gdb) clear R_ReadConsole (gdb) continue
Fortran symbols need an underline appended.
mingw32
version of gdb
. It does
often work with the cygwin
version.cygwin gdb
was able to catch but which
terminated the mingw32 gdb
.If you have an X server available on the PC, there is a version
of DDD
available that runs under the cygwin emulation
layer (follow the links at
http://www.cygwin.com) and provides a graphical user interface
to gdb
. Another (Windows-native) GUI for
gdb
is Insight
, part of the latest
cygwin
version of gdb
You need to do two things:
(a) Write a wrapper to export the symbols you want to call from
R as extern "C"
.
(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 (gcc
)
...\bin\Rcmd SHLIB X.cc X_main.cc
or (VC++, which requires extension .cpp
)
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
.cpp
)
bcc32 -u- -WDE X.cpp X_main.cpp
and call the entry point(s) in X_R
, such as
X_main
. 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 is in package cxx_0.0-x.tar.gz
in the
src/contrib/Devel
section on CRAN, and that can be
compiled as package in the usual way on Windows.
The Rgui.exe
console is a Windows application:
writing to stdout
or stderr
will not
produce output in the console. (This will work with
Rterm.exe
.) Use Rprintf
or
REprintf
instead. These are declared in header file
R_ext/PrtUtil.h
.
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
Rgui
console. Use one of the subroutines
dblepr
, intpr
or realpr
documented
in the `Writing R Extensions' manual.
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, call R_ProcessEvents()
periodically
from your compiled code. If you want output to be updated on the
console, call R_FlushConsole()
and then
R_ProcessEvents()
.
Yes, we know that for example Rcmd check
can fail
with some versions of Perl on some 16-bit Windows installations.
Usually there are alternatives such as make
pkgcheck-foo
, but you could try getting a modern operating
system!
ripley@stats.ox.ac.uk