The R Project SVN R

Rev

Rev 21708 | Blame | Last modification | View Log | Download | RSS feed

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<meta name="generator" content=
"HTML Tidy for Windows (vers 1st April 2002), see www.w3.org">
<title>R for Windows FAQ</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="R for Windows FAQ">
<meta name="generator" content="makeinfo 4.2">
<link href="http://www.gnu.org/software/texinfo/" rel=
"generator-home">
</head>
<body>
<h1>R for Windows FAQ</h1>

<h2>Version for <tt>rw1070</tt></h2>

<address>B. D. Ripley</address>

<hr>
<h2>Table of Contents</h2>

<ul>
<li><a name="toc_Introduction"></a> <a href="#Introduction">1
Introduction</a></li>

<li><a name="toc_Installation%20and%20Usage"></a> <a href=
"#Installation%20and%20Usage">2 Installation and Usage</a> 
<ul>
<li><a href=
"#Where%20can%20I%20find%20the%20latest%20version%3f">2.1 Where can
I find the latest version?</a></li>

<li><a href="#How%20do%20I%20install%20R%20for%20Windows%3f">2.2
How do I install R for Windows?</a></li>

<li><a href="#How%20do%20I%20run%20it%3f">2.3 How do I run
it?</a></li>

<li><a href="#How%20do%20I%20UNinstall%20R%3f">2.4 How do I
UNinstall R?</a></li>

<li><a href="#What's%20the%20best%20way%20to%20upgrade%3f">2.5
What's the best way to upgrade?</a></li>

<li><a href=
"#There%20seems%20to%20be%20a%20limit%20on%20the%20memory%20it%20uses!">
2.6 There seems to be a limit on the memory it uses!</a></li>

<li><a href=
"#How%20can%20I%20keep%20workspaces%20for%20different%20projects%20in%20different%20directories%3f">
2.7 How can I keep workspaces for different projects in different
directories?</a></li>

<li><a href="#How%20do%20I%20print%20from%20R%3f">2.8 How do I
print from R?</a></li>

<li><a href="#Can%20I%20use%20R%20BATCH%3f">2.9 Can I use <code>R
BATCH</code>?</a></li>

<li><a href=
"#Can%20I%20use%20rw1070%20with%20ESS%20and%20(X)emacs%3f">2.10 Can
I use rw1070 with ESS and (X)emacs?</a></li>

<li><a href=
"#What%20are%20HOME%20and%20working%20directories%3f">2.11 What are
HOME and working directories?</a></li>

<li><a href="#How%20do%20I%20set%20environment%20variables%3f">2.12
How do I set environment variables?</a></li>

<li><a href="#R%20can't%20find%20my%20file">2.13 R can't find my
file, but I know it is there!</a></li>

<li><a href="#Does%20R%20use%20the%20Registry%3f">2.14 Does R use
the Registry?</a></li>

<li><a href=
"#Entering%20certain%20characters%20crashes%20Rgui.">2.15 Entering
certain characters crashes Rgui.</a></li>

<li><a href="#The%20internet%20download%20functions%20fail.">2.16
The internet download functions fail.</a></li>

<li><a href="#Other%20strange%20crashes.">2.17 Other strange
crashes.</a></li>
</ul>
</li>

<li><a name="toc_Packages"></a> <a href="#Packages">3 Packages</a> 
<ul>
<li><a href=
"#Can%20I%20install%20packages%20(libraries)%20in%20this%20version%3f">
3.1 Can I install packages (libraries) in this version?</a></li>

<li><a href=
"#I%20don't%20have%20permission%20to%20write%20to%20the%20rw1070%5clibrary%20directory">
3.2 I don't have permission to write to the
<code>rw1070\library</code> directory.</a></li>

<li><a href=
"#The%20packages%20I%20installed%20do%20not%20appear%20in%20the%20HTML%20help%20system">
3.3 The packages I installed do not appear in the HTML help
system.</a></li>

<li><a href=
"#My%20functions%20are%20not%20found%20by%20the%20HTML%20help%20search%20system.">
3.4 My functions are not found by the HTML help search
system.</a></li>

<li><a href="#Loading%20a%20package%20fails.">3.5 Loading a package
fails.</a></li>

<li><a href="#Package%20TclTk%20does%20not%20work.">3.6 Package
TclTk does not work.</a></li>

<li><a href=
"#Hyperlinks%20in%20Compiled%20HTML%20do%20not%20work.">3.7
Hyperlinks in Compiled HTML sometimes do not work.</a></li>

<li><a href="#update.packages()%20fails">3.8
<code>update.packages()</code> fails</a></li>
</ul>
</li>

<li><a name="toc_Windows%20Features"></a> <a href=
"#Windows%20Features">4 Windows Features</a> 
<ul>
<li><a href=
"#What%20should%20I%20expect%20to%20behave%20differently%20from%20the%20Unix%20version">
4.1 What should I expect to behave differently from the Unix
version of R?</a></li>

<li><a href="#I%20hear%20about%20some%20nifty%20features.">4.2 I
hear about some nifty features: please tell me about them!</a></li>

<li><a href="#Circles%20appear%20as%20ovals%20on%20screen">4.3
Circles appear as ovals on screen</a></li>

<li><a href=
"#How%20do%20I%20move%20focus%20to%20a%20graphics%20window%20or%20the%20console%3f">
4.4 How do I move focus to a graphics window or the
console?</a></li>
</ul>
</li>

<li><a name="toc_Workspaces"></a> <a href="#Workspaces">5
Workspaces</a> 
<ul>
<li><a href=
"#My%20workspace%20gets%20saved%20in%20a%20strange%20place.%20How%20do%20I%20stop%20this%3f">
5.1 My workspace gets saved in a strange place: how do I stop
this?</a></li>

<li><a href=
"#How%20do%20I%20store%20my%20workspace%20in%20a%20different%20place%3f">
5.2 How do I store my workspace in a different place?</a></li>

<li><a href=
"#Can%20I%20load%20workspaces%20saved%20under%20Unix%2fGNU-Linux%3f">
5.3 Can I load workspaces saved under Unix/GNU-Linux?</a></li>
</ul>
</li>

<li><a name="toc_The%20R%20Console%20and%20Fonts"></a> <a href=
"#The%20R%20Console%20and%20Fonts">6 The R Console and Fonts</a> 
<ul>
<li><a href=
"#I%20would%20like%20to%20be%20able%20to%20use%20Japanese%20fonts">6.1
I would like to be able to use Japanese fonts</a></li>

<li><a href=
"#I%20don't%20see%20characters%20with%20accents%20at%20the%20R%20console">
6.2 I don't see characters with accents at the R console, for
example in ?text.</a></li>

<li><a href=
"#The%20output%20to%20the%20console%20seems%20to%20be%20delayed">6.3
When using Rgui the output to the console seems to be
delayed.</a></li>

<li><a href="#Long%20lines%20seem%20to%20be%20truncated.">6.4 Long
lines in the console or pager are truncated.</a></li>
</ul>
</li>

<li><a name="toc_Building%20from%20Source"></a> <a href=
"#Building%20from%20Source">7 Building from Source</a> 
<ul>
<li><a href="#How%20can%20I%20compile%20R%20from%20source%3f">7.1
How can I compile R from source?</a></li>

<li><a href="#Can%20I%20use%20a%20fast%20BLAS%3f">7.2 Can I use a
fast BLAS?</a></li>

<li><a href="#How%20do%20I%20include%20compiled%20C%20code%3f">7.3
How do I include compiled C code?</a></li>

<li><a href=
"#How%20do%20I%20debug%20code%20that%20I%20have%20compiled%20and%20dyn.load-ed%3f">
7.4 How do I debug code that I have compiled and
dyn.load-ed?</a></li>

<li><a href="#How%20do%20I%20include%20C++%20code%3f">7.5 How do I
include C++ code?</a></li>

<li><a href=
"#The%20output%20from%20my%20C%20code%20disappears.">7.6 The output
from my C code disappears. Why?</a></li>

<li><a href=
"#The%20output%20from%20my%20Fortran%20code%20disappears.">7.7 The
output from my Fortran code disappears. Why?</a></li>

<li><a href=
"#The%20console%20freezes%20when%20my%20compiled%20code%20is%20running">
7.8 The console freezes when my compiled code is running.</a></li>
</ul>
</li>
</ul>

<a name="Top"></a>  
<hr>
<a name="Introduction"></a> 
<h2>1 Introduction</h2>

<p>This FAQ is for the Windows port of R: it describes features
specific to that version. The main R FAQ can be found at<br>
</p>

<pre>
<a href=
"http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html">http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html</a>.
</pre>

<p>The information here applies only to recent versions of R for
Windows, (<code>1.4.0</code> or later); the current version is
often called something like <code>rw1070</code> (although not
officially).</p>

<hr>
<a name="Installation%20and%20Usage"></a> 
<h2>2 Installation and Usage</h2>

<a name="Where%20can%20I%20find%20the%20latest%20version%3f"></a> 
<h3>2.1 Where can I find the latest version?</h3>

<p>Go to any CRAN site (see <a href=
"http://cran.r-project.org/mirrors.html">http://cran.r-project.org/mirrors.html</a>
for a list), navigate to the <code>bin/windows/base</code>
directory and collect the files you need. There are two versions of
the distribution.</p>

<p>1) <code>rw1070.exe</code> is about 19Mb and gives a complete
installation.</p>

<p>2) Directory <code>miniR</code> contains <code>miniR.exe</code>
and eight files <code>miniR-?.bin</code>. You can put
<code>miniR.exe</code> and <code>miniR-1.bin</code> on one floppy
and the remaining <code>miniR-?.bin</code> on a floppy each. <a
name="How%20do%20I%20install%20R%20for%20Windows%3f"></a></p>

<h3>2.2 How do I install R for Windows?</h3>

<p>First, you need Windows 95/98/ME/NT4/2000/XP: 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).</p>

<p>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.)</p>

<p>The simplest way is to use <code>rw1070.exe</code> or
<code>miniR.exe</code>. 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).</p>

<p>For a manual installation, 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 <code>unzip</code>).
All the files will unpack into a directory <code>rw1070</code>.</p>

<p>Choose a working directory for R. If you installed manually,
make a shortcut to <code>rw1070\bin\Rgui.exe</code> 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.</p>

<p>You may also want to add command-line arguments at the end of
the Target field, for example <code>--sdi
--max-mem-size=40M</code>. You can also set environment variables
at the end of the Target field, for example
<code>R_LIBS=p:/myRlib</code>. <a name=
"How%20do%20I%20run%20it%3f"></a></p>

<h3>2.3 How do I run it?</h3>

<p>Just double-click on the shortcut you prepared at
installation.</p>

<p>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.</p>

<p>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
<code>tcsh</code> or <code>bash</code>. (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.) <a name="How%20do%20I%20UNinstall%20R%3f"></a></p>

<h3>2.4 How do I UNinstall R?</h3>

<p>Normally you can do this from the R group on the Start Menu or
from the <code>Add/Remove Programs</code> in the Control Panel. If
it does not appear there or if you want to remove an old version,
run <code>unins000.exe</code> in the top-level installation
directory.</p>

<p>Uninstalling R only removes files from the initial installation,
not for example packages you have installed.</p>

<p>If all else fails, you can just delete the whole directory in
which R was installed. <a name=
"What's%20the%20best%20way%20to%20upgrade%3f"></a></p>

<h3>2.5 What's the best way to upgrade?</h3>

<p>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 <code>update.packages()</code> (from the 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 prefer.
<a name=
"There%20seems%20to%20be%20a%20limit%20on%20the%20memory%20it%20uses!">
</a></p>

<h3>2.6 There seems to be a limit on the memory it uses!</h3>

<p>Indeed there is. It is set by the command-line flag
<code>--max-mem-size</code> (see <a href=
"#How%20do%20I%20install%20R%20for%20Windows%3f">How do I install R
for Windows?</a>) and defaults to the smaller of the amount of
physical RAM in the machine and 1Gb. It can be set to any amount
over 10M. (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.
Because of the way the memory manager works, it is possible that
there will be free memory but R will not be able to make use of
it.</p>

<p>Use <code>?Memory</code> and <code>?memory.size</code> for
information about memory usage. The limit can be raised by calling
<code>memory.limit</code> within a running R session.</p>

<p>We have found that starting R with too large a value of
<code>--max-mem-size</code> may fail: the limit seemed to be about
1.7Gb on Windows 2000 Professional.</p>

<p>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). <a name=
"How%20can%20I%20keep%20workspaces%20for%20different%20projects%20in%20different%20directories%3f">
</a></p>

<h3>2.7 How can I keep workspaces for different projects in
different directories?</h3>

<p>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.</p>

<p>Alternatively, start R by double-clicking on a saved
<code>.RData</code> file in the directory for the project you want
to use, or drag-and-drop a file with extension <code>.RData</code>
onto an R shortcut. In either case, the working directory will be
set to that containing the file. <a name=
"How%20do%20I%20print%20from%20R%3f"></a></p>

<h3>2.8 How do I print from R?</h3>

<p>It depends what you want to print.</p>

<ul>
<li>You can print the graphics window from its menu or by using
<code>dev.print</code> with suitable arguments (see its help page:
most likely <code>dev.print(win.graph)</code> will work).</li>

<li>You can print from the R console or pager by <code>File |
Print</code>. (This will print the selection if there is one,
otherwise the whole console or pager contents.)</li>

<li>You can print help files from the pager or HTML browser.</li>

<li>If you have configured <code>RHOME\bin\helpPRINT.bat</code> and
have LaTeX installed you can print help files by
<code>help(fn_name, offline=TRUE)</code>.</li>
</ul>

<a name="Can%20I%20use%20R%20BATCH%3f"></a> 
<h3>2.9 Can I use <code>R BATCH</code>?</h3>

<p>Yes, if you have Perl. The Windows analogue is <code>Rcmd
BATCH</code>: use <code>Rcmd BATCH --help</code> for full
details.</p>

<p>Otherwise you can set up a batch file using
<code>Rterm.exe</code>. A sample batch file might contain (as one
line)<br>
</p>

<pre>
path_to_R\bin\Rterm.exe --no-restore --no-save &lt; %1 &gt; %1.out
</pre>

<a name=
"Can%20I%20use%20rw1070%20with%20ESS%20and%20(X)emacs%3f"></a> 
<h3>2.10 Can I use rw1070 with ESS and (X)emacs?</h3>

<p>Yes. Recent versions of ESS (e.g. 5.1.20) come with support for
this version of R, and there is support for interrupting the R
process from ESS (by <code>C-c C-c</code>).</p>

<p>For help with ESS, please send email to <a href=
"mailto:ESS-help@stat.ethz.ch">ESS-help@stat.ethz.ch</a>, not the R
mailing lists. <a name=
"What%20are%20HOME%20and%20working%20directories%3f"></a></p>

<h3>2.11 What are HOME and working directories?</h3>

<p>Several places in the documentation use these terms.</p>

<p>The working directory is the directory from which
<code>Rgui</code> or <code>Rterm</code> 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
<code>getwd()</code>.</p>

<p>The home directory is set as follows:<br>
If environment variable <code>R_USER</code> is set, its value is
used.<br>
Otherwise if environment variable <code>HOME</code> is set, its
value is used.<br>
Otherwise if environment variables <code>HOMEDRIVE</code> and
<code>HOMEPATH</code> are set, the value is
<code>${HOMEDRIVE}${HOMEPATH}</code>.<br>
If all of these fail, the current working directory is used.</p>

<p>You can find this from R code by
<code>Sys.getenv("R_USER")</code>. <a name=
"How%20do%20I%20set%20environment%20variables%3f"></a></p>

<h3>2.12 How do I set environment variables?</h3>

<p>Environment variables can be set in R in three different
ways.</p>

<ol type="1" start="1">
<li>On the command line as name=value pairs. For example in the
shortcut to <code>RGui</code> you could have<br>
<pre>
path_to_R\bin\Rgui.exe HOME=p:/ R_LIBS=p:/myRlib
</pre>
</li>

<li>In an environment file <code>.Renviron</code> in the working
directory or your home directory, for example containing the
line<br>
<pre>
R_LIBS=p:/myRlib
</pre>

<p>If you have permission to do so, you can also create an
environment file <code>etc\Renviron.site</code> 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
<code>.Renviron</code> or on the command line.)</p>

<p>See <code>?Startup</code> for more details of environment
files.</p>
</li>

<li>For all applications via Windows. How you set an environment
variable is system specific: in Windows 9x you can set them in
<code>autoexec.bat</code> or in an MS-DOS window from which you
launch <code>Rgui</code> / <code>Rterm</code>. 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.</li>
</ol>

<p>The order of precedence for environmental variables is the order
in which these options are listed, that is the command line then
<code>.Renviron</code> then the inherited environment. <a name=
"R%20can't%20find%20my%20file"></a></p>

<h3>2.13 R can't find my file, but I know it is there!</h3>

<p>How did you specify it? Backslashes have to be doubled in R
character strings, so for example one needs
<code>"d:\\rw1070\\library\\xgobi\\scripts\\xgobi.bat"</code>. Make
life easier for yourself by using forward slashes as path
separators: they do work under Windows.</p>

<p>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
<code>PROGRA~1</code>; you can get it as the `MS-DOS name' from the
Properties of the file on most versions of Windows, and from
<code>dir /X</code> in a <code>Command Prompt</code> window on
2000/XP). <a name="Does%20R%20use%20the%20Registry%3f"></a></p>

<h3>2.14 Does R use the Registry?</h3>

<p>Not itself.</p>

<p>The installers set some entries to allow uninstallation. In
addition they set a Registry key
<code>LOCAL_MACHINE\Software\R-core\R</code> giving the version and
install path. Again, this is not used by R itself, but it will be
used by the DCOM interface (<a href=
"http://cran.r-project.org/other-software.html">http://cran.r-project.org/other-software.html</a>).
Finally, a file association for extension <code>.RData</code> is
set in the Registry.</p>

<p>You can add the Registry entries by running
<code>RSetReg.exe</code> in the <code>bin</code> folder, and remove
them by running this with argument <code>/U</code>. Note that the
settings are all per machine and not per user, and that this
neither sets up nor removes the file associations. <a name=
"Entering%20certain%20characters%20crashes%20Rgui."></a></p>

<h3>2.15 Entering certain characters crashes Rgui.</h3>

<p>This used to happen occasionally, and all the occurrences we
have solved have been traced to faulty versions of
<code>msvcrt.dll</code>. We have installed a workaround as from
<code>rw1051</code> that seems to avoid this.</p>

<p>If it still happens, try extracting the one to be found in the
self-extracting archive <a href=
"ftp://ftp.microsoft.com/softlib/mslfiles/msvcrt.exe">ftp://ftp.microsoft.com/softlib/mslfiles/msvcrt.exe</a>
and put it in the <code>rw1070\bin</code> directory. Removing
<code>msvcrt.dll</code> 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 <code>rw1070\bin</code> directory
early in your path.</p>

<p>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. <a name=
"The%20internet%20download%20functions%20fail."></a></p>

<h3>2.16 The internet download functions fail.</h3>

<p>for example <code>update.packages</code> and the menu items on
the Packages menu.</p>

<p>We have had several reports of this, although they do work for
us on <em>all</em> of our machines. There are two known possible
fixes.</p>

<p>(a) Use the alternative <code>internet2.dll</code> by starting R
with the flag <code>--internet2</code> (see <a href=
"#How%20do%20I%20install%20R%20for%20Windows%3f">How do I install R
for Windows?</a>) which uses the Internet Explorer internals (and
so needs Internet Explorer 4 or later installed).</p>

<p>(b) A proxy needs to be set up: see <code>?download.file</code>.
<a name="Other%20strange%20crashes."></a></p>

<h3>2.17 Other strange crashes.</h3>

<p>Some users have found that <code>Rgui.exe</code> 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 this crash.</p>

<p>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.</p>

<hr>
<a name="Packages"></a> 
<h2>3 Packages</h2>

<a name=
"Can%20I%20install%20packages%20(libraries)%20in%20this%20version%3f">
</a> 
<h3>3.1 Can I install packages (libraries) in this version?</h3>

<p>Yes, but you will need a lot of tools to do so, unless the
author or the maintainers of the <code>bin/windows/contrib</code>
section on CRAN have been kind enough to provide a pre-compiled
version for Windows as a <code>.zip</code> file.</p>

<p>You can install pre-compiled packages either from CRAN or from a
local <code>.zip</code> file by using
<code>install.packages</code>: see its help page. There are menu
items on the <code>Packages</code> menu to provide a
point-and-click interface to package installation.</p>

<p>Note that the pre-compiled versions on CRAN are unsupported: see
<a href=
"http://cran.r-project.org/bin/windows/contrib/ReadMe">http://cran.r-project.org/bin/windows/contrib/ReadMe</a>.</p>

<p>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 <code>rw1070.exe</code>. Then read the file
<code>README.packages</code>. You will need to collect and install
several tools to use this: you can download them via the portal at
<a href=
"http://www.stats.ox.ac.uk/pub/Rtools/">http://www.stats.ox.ac.uk/pub/Rtools/</a>.
Once you have done so, just run <code>Rcmd INSTALL pkgname</code>.
To check the package (including running all the examples on its
help pages and in its test suite, if any) use <code>Rcmd check
pkgname</code>: see the <em>`Writing R Extensions'</em> manual.</p>

<p>Note that this is rather so tricky; please do ensure that you
have followed the instructions <strong>exactly</strong>. At least
90% of the questions asked are because people have not done so. <a
name=
"I%20don't%20have%20permission%20to%20write%20to%20the%20rw1070%5clibrary%20directory">
</a></p>

<h3>3.2 I don't have permission to write to the
<code>rw1070\library</code> directory.</h3>

<p>You can install packages anywhere and use the environment
variable <code>R_LIBS</code> (see <a href=
"#How%20do%20I%20set%20environment%20variables%3f">How do I set
environment variables?</a>) to point to the library
location(s).</p>

<p>Suppose your packages are installed in <code>p:\myRlib</code>.
Then you can EITHER<br>
</p>

<pre>
set the environment variable R_LIBS to p:\myRlib
</pre>

<p>OR use a package by, e.g.<br>
</p>

<pre>
library(MASS, lib.loc="p:/myRlib")
</pre>

<a name=
"The%20packages%20I%20installed%20do%20not%20appear%20in%20the%20HTML%20help%20system">
</a> 
<h3>3.3 The packages I installed do not appear in the HTML help
system.</h3>

<p>The HTML search only works for packages installed in
<code>rw1070\library</code>.</p>

<p>To update the HTML indices after you have installed a
pre-compiled package, run at the R prompt.<br>
</p>

<pre>
&gt; link.html.help()
</pre>

<p>This is done automatically when installing from the Packages
menu or by <code>install.packages()</code>, and when
<code>help.start</code> is run, provided you have write permission
in <code>rw1070\library</code>. <a name=
"My%20functions%20are%20not%20found%20by%20the%20HTML%20help%20search%20system.">
</a></p>

<h3>3.4 My functions are not found by the HTML help search
system.</h3>

<p>The following conditions need to hold for functions in a package
you installed.</p>

<ul>
<li>the package is installed in <code>rw1070\library</code>.</li>

<li>the package contains a <code>CONTENTS</code> file in its
top-level directory.</li>

<li>you updated the indices as described in the answer to Q3.3
after installing the package.</li>
</ul>

<p>If those all hold true, this works for us.</p>

<p>If the help search system does not work <em>at all</em>, this
probably indicates that Java support is either not installed or not
enabled in your browser. Recent versions of browsers have made Java
support optional: for example it is optional in Netscape 6.x and
Opera, and may not be installed for IE6 on Windows XP. <a name=
"Loading%20a%20package%20fails."></a></p>

<h3>3.5 Loading a package fails.</h3>

<p>Is the package compiled for this version of R? Many of the
packages need to be compiled for a fairly recent version. (As from
version 1.5.0, R will warn if a package is used that was built
under a <em>later</em> version.)</p>

<p>You can tell the version the package was compiled for by looking
at the <code>Built:</code> line in its <code>DESCRIPTION</code>
file or at the <code>Version</code> tab of its DLL (if it has one)
in the <code>libs</code> directory. (Right-click on the DLL in
Windows Explorer and select <code>Version</code> tab of the
<code>Properties</code>, or use the <code>DLL.version</code>
function inside R.) If there is no <code>Built:</code> line or
version tab, the package was compiled too long ago. <a name=
"Package%20TclTk%20does%20not%20work."></a></p>

<h3>3.6 Package TclTk does not work.</h3>

<p>For package <code>tcltk</code> to work (try
<code>demo(tkdensity)</code> or <code>demo(tkttest)</code> after
<code>library(tcltk)</code>) you need to have Tcl installed.
Download ActiveTcl 8.3.x from <a href=
"http://aspn.activestate.com/ASPN/Downloads/ActiveTcl/">http://aspn.activestate.com/ASPN/Downloads/ActiveTcl/</a>
and install it. (Most of the installers that ActiveTcl uses will
put the <code>bin</code> directory containing the Tcl and Tk DLLs
in your path, but you should check. From R, run
<code>Sys.getenv("PATH")</code> to do so.) Note that you do need
8.3.x and not 8.4.x: follow the links to 8.4.x and you will find
8.3.x available there.</p>

<p>You then need to set the environment variable
<code>TCL_LIBRARY</code>(see <a href=
"#How%20do%20I%20set%20environment%20variables%3f">How do I set
environment variables?</a>), to something like <code>c:/Program
Files/Tcl/lib/tcl8.3</code>. (The startup code for the package will
warn you if this is unset. NB: do not quote the path, even if as
here it contains spaces. If you forget, you can set the variable
inside R by something like<br>
</p>

<pre>
    Sys.putenv("TCL_LIBRARY"="c:/Program Files/Tcl/lib/tcl8.3")
</pre>

.) Similarly, you can set the path if needed by something like <br>
<pre>
    Sys.putenv(PATH=paste(Sys.getenv("PATH"), "c:/Tcl/bin", sep = ";"))
</pre>

<a name="Hyperlinks%20in%20Compiled%20HTML%20do%20not%20work."></a>

<h3>3.7 Hyperlinks in Compiled HTML sometimes do not work.</h3>

<p>They may well not work between packages installed in different
libraries. This is solved under Unix using symbolic links which
Windows does not implement. <a name=
"update.packages()%20fails"></a></p>

<h3>3.8 <code>update.packages()</code> fails</h3>

<p>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
<code>update.packages()</code> (or the menu equivalent) in a new
session.</p>

<p>If you put <code>library(foo)</code> in your
<code>.Rprofile</code> you will need to start R with
<code>--vanilla</code> to be able to update package
<code>foo</code>.</p>

<hr>
<a name="Windows%20Features"></a> 
<h2>4 Windows Features</h2>

<a name=
"What%20should%20I%20expect%20to%20behave%20differently%20from%20the%20Unix%20version">
</a> 
<h3>4.1 What should I expect to behave differently from the Unix
version of R?</h3>

<ul>
<li>R commands can be interrupted by &lt;Esc&gt; in
<code>Rgui.exe</code> and &lt;Ctrl-break&gt; or &lt;Ctrl-C&gt; in
<code>Rterm.exe</code>: &lt;Ctrl-C&gt; is used for copying in the
GUI version.</li>

<li>Command-line editing is always available, but is simpler than
the readline-based editing on Unix. For <code>Rgui.exe</code>, the
menu item `Help | Console' will give details. For
<code>Rterm.exe</code> see file <code>README.rterm</code>.</li>

<li>Using <code>help.start()</code> does not automatically send
help requests to the browser: use
<code>options(htmlhelp=TRUE)</code> to turn this on.</li>

<li>The HTML help system can only access packages installed in the
standard library.</li>

<li>Paths to files (e.g. in <code>source()</code>) can be specified
with either "/" or "\\".</li>

<li><code>system()</code> is slightly different: see its help page
and that of <code>shell()</code>.</li>
</ul>

<a name="I%20hear%20about%20some%20nifty%20features."></a> 
<h3>4.2 I hear about some nifty features: please tell me about
them!</h3>

<p>You have read the <code>README</code>? 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 <code>png</code>,
<code>jpeg</code>, <code>bmp</code>, <code>postscript</code>,
<code>PDF</code> or <code>metafile</code>. There are right-click
menus giving shortcuts to menu items, and optionally toolbars with
buttons giving shortcuts to frequent operations.</p>

<p>If you resize the R console the <code>options(width=)</code> is
automatically set to the console width (unless disabled in the
configuration file).</p>

<p>The graphics has a history mechanism. As the README says:</p>

<blockquote>`The History menu allows the recording of plots. When
plots have been recorded they can be reviewed by &lt;PgUp&gt; and
&lt;PgDn&gt;, saved and replaced. Recording can be turned on
automatically (the Recording item on the list) or individual plots
can be added (Add or the &lt;INS&gt; key). The whole plot history
can be saved to or retrieved from an R variable in the global
environment. 
<p>There is only one graphics history shared by all the windows
devices.'</p>
</blockquote>

<p>The R console and graphics windows have configuration files
stored in the <code>RHOME\etc</code> directory called
<code>Rconsole</code> and <code>Rdevga</code>; you can keep
personal copies in your <code>HOME</code> directory. They contain
comments which should suffice for you to edit them to your
preferences. For more details see <code>?Rconsole</code>. There is
a Preferences editor invoked from the <code>Edit</code> menu which
can be used to edit the file <code>Rconsole</code>. <a name=
"Circles%20appear%20as%20ovals%20on%20screen"></a></p>

<h3>4.3 Circles appear as ovals on screen</h3>

<p>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
<code>windows</code> or as options: see <code>?windows</code>.
(Typically these are of the order of 80.)</p>

<p>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! <a name=
"How%20do%20I%20move%20focus%20to%20a%20graphics%20window%20or%20the%20console%3f">
</a></p>

<h3>4.4 How do I move focus to a graphics window or the
console?</h3>

<p>You may want to do this from within a function, for example when
calling <code>identify</code> or <code>readline</code>. Use the
function <code>bringToTop()</code>. With its default argument it
brings the active graphics window to the top and gives it focus.
With argument <code>-1</code> it brings the console to the top and
gives it focus.</p>

<p>This works for <code>Rgui.exe</code> in MDI and SDI modes, and
can be used for graphics windows from <code>Rterm.exe</code>
(although Windows may not always act on it).</p>

<hr>
<a name="Workspaces"></a> 
<h2>5 Workspaces</h2>

<a name=
"My%20workspace%20gets%20saved%20in%20a%20strange%20place.%20How%20do%20I%20stop%20this%3f">
</a> 
<h3>5.1 My workspace gets saved in a strange place: how do I stop
this?</h3>

<p>Have you changed the working directory?: see Q5.2. <a name=
"How%20do%20I%20store%20my%20workspace%20in%20a%20different%20place%3f">
</a></p>

<h3>5.2 How do I store my workspace in a different place?</h3>

<p>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.</p>

<p>From the command line you can change the working directory by
the function <code>setwd</code>: see its help page. <a name=
"Can%20I%20load%20workspaces%20saved%20under%20Unix%2fGNU-Linux%3f">
</a></p>

<h3>5.3 Can I load workspaces saved under Unix/GNU-Linux?</h3>

<p>Yes. All ports of R use the same format for workspaces, so they
are interchangeable (for the same 1.x.? version of R, at
least).</p>

<hr>
<a name="The%20R%20Console%20and%20Fonts"></a> 
<h2>6 The R Console and Fonts</h2>

<a name=
"I%20would%20like%20to%20be%20able%20to%20use%20Japanese%20fonts"></a>

<h3>6.1 I would like to be able to use Japanese fonts</h3>

<p>for example, in the console and to annotate graphs.</p>

<p>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<br>
</p>

<pre>
par(font=, font.lab=, font.main=, font.sub=)
</pre>

<p>Nineteen fonts are specified (as 1 to 19) by default: you can
add to these (up to 13 more) or replace them. <a name=
"I%20don't%20see%20characters%20with%20accents%20at%20the%20R%20console">
</a></p>

<h3>6.2 I don't see characters with accents at the R console, for
example in ?text.</h3>

<p>You need to specify a font in Rconsole (see Q4.2) that supports
Latin1 encoding. The default, <code>Courier New</code>, does on our
systems, as does <code>FixedSys</code>. This may be a problem in
other locales, especially for non-Western European languages.</p>

<p>Support for these characters within <code>Rterm</code> 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. <a name=
"The%20output%20to%20the%20console%20seems%20to%20be%20delayed"></a></p>

<h3>6.3 When using Rgui the output to the console seems to be
delayed.</h3>

<p>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: &lt;Ctrl-W&gt; toggles the setting.</p>

<p>If you are sourcing R code or writing from a function, there is
another option. A call to the R function
<code>flush.console()</code> will write out the buffer and so
update the console. <a name=
"Long%20lines%20seem%20to%20be%20truncated."></a></p>

<h3>6.4 Long lines in the console or pager are truncated.</h3>

<p>They only <strong>seem</strong> 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 &lt;CTRL + left/right
arrow&gt; keys to scroll horizontally.</p>

<hr>
<a name="Building%20from%20Source"></a> 
<h2>7 Building from Source</h2>

<a name="How%20can%20I%20compile%20R%20from%20source%3f"></a> 
<h3>7.1 How can I compile R from source?</h3>

<p>Get the R sources. Suppose you want to compile R-1.7.0. Start in
a directory whose path does not contain spaces, and run<br>
</p>

<pre>
tar zxvf R-1.7.0.tgz
cd R-1.7.0
cd src\gnuwin32
</pre>

<p>Now read the <code>INSTALL</code> file and set up all the tools
needed. Then you can just use <code>make</code>, sit back and wait.
(A complete build takes about 5 minutes on a 1GHz PIII with a fast
local disc.)</p>

<p>You may need to compile under a case-honouring file system: we
found that a <code>samba</code>-mounted file system (which maps all
file names to lower case) did not work. <a name=
"Can%20I%20use%20a%20fast%20BLAS%3f"></a></p>

<h3>7.2 Can I use a fast BLAS?</h3>

<p>Fast BLAS (Basic Linear Algebra Subprograms, <a href=
"http://www.netlib.org/blas/faq.html">http://www.netlib.org/blas/faq.html</a>)
routines are used to speed up numerical linear algebra. There is
support in the R sources for the `tuned' BLAS called ATLAS (<a
href=
"http://math-atlas.sourceforge.net">http://math-atlas.sourceforge.net</a>).
The savings can be appreciable: on a 366MHz PIIM and a 1000 x 1000
matrix <code>La.svd</code> took 182 sec with the standard BLAS and
59 sec with ATLAS. Because ATLAS is tuned to a particular chip we
can't use it generally: the optimal routines for a PIII or an
Athlon XP are quite different and neither will not run at all on a
PII.</p>

<p>BLAS support is supplied by the single DLL
<code>R_HOME\bin\Rblas.dll</code>, 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
<code>bin/windows/contrib/ATLAS</code>.</p>

<p>If you are building R from source, in the file
<code>MkRules</code> there are macros <code>USE_ATLAS</code> and
<code>ATLAS_PATH</code>. Set <code>USE_ATLAS = YES</code> and
<code>ATLAS_PATH</code> 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 compiler. <a name=
"How%20do%20I%20include%20compiled%20C%20code%3f"></a></p>

<h3>7.3 How do I include compiled C code?</h3>

<p>We strongly encourage you to do this <em>via</em> building an R
package: see the <em>`Writing R Extensions'</em> manual. In any
event you should install the parts of the R system for building R
packages (in <code>rw1070.exe</code>), and get and install the
tools (including Perl) and compilers mentioned in the file
<code>readme.packages</code> contained therein. Then you can
use<br>
</p>

<pre>
...\bin\Rcmd SHLIB foo.c bar.f
</pre>

<p>to make <code>foo.dll</code>. Use <code>...\bin\Rcmd SHLIB
--help</code> for further options, or see <code>?SHLIB</code>.</p>

<p>If you want to use Visual C++, Borland C++ or other compilers,
see the appropriate section in <code>readme.packages</code>. <a
name=
"How%20do%20I%20debug%20code%20that%20I%20have%20compiled%20and%20dyn.load-ed%3f">
</a></p>

<h3>7.4 How do I debug code that I have compiled and
dyn.load-ed?</h3>

<p>You will need a suitable version of <code>gdb</code>: 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 <em>just-in-time</em> debugger to catch
crashes, consider <code>Dr. Mingw</code> from <a href=
"http://mefriss1.swan.ac.uk/~jfonseca/gnu-win32/software/drmingw/">http://mefriss1.swan.ac.uk/~jfonseca/gnu-win32/software/drmingw/</a>.
That will be able to pinpoint the error, most effectively if you
build a version of R with debugging information as described
below.</p>

<p>First, build a version of the R system with debugging
information by<br>
</p>

<pre>
make clean
make DEBUG=T
</pre>

<p>and make a debug version of your package by<br>
</p>

<pre>
make pkgclean-mypkg
make DEBUG=T pkg-mypkg
</pre>

<p>Then you can debug by<br>
</p>

<pre>
gdb /path/to/rw1070/bin/Rgui.exe
</pre>

<p>However, note</p>

<ul>
<li><code>gdb</code> will only be able to find the source code if
we run in the location where the source was compiled
(<code>rw1070/src/gnuwin32</code> for the main system,
<code>rw1070/src/library/mypkg/src</code> for a package), unless
told otherwise by the <code>directory</code> command. It is most
convenient to set a list of code locations via
<code>directory</code> commands in the file <code>.gdbinit</code>
in the directory from which <code>gdb</code> is run.</li>

<li>It is only possible to set breakpoints in a DLL after the DLL
has been loaded. So a way to examine the function
<code>tukeyline</code> in package <code>eda</code> might be<br>
<pre>
     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&gt; library(eda)
     (gdb) break tukeyline
     (gdb) clear R_ReadConsole
     (gdb) continue
</pre>

<p>Fortran symbols need an underline appended.</p>
</li>

<li>Windows has little support for signals, so the usual idea of
running a program under a debugger and sending it a signal to
interrupt it and drop control back to the debugger does not work
with a <code>mingw</code> version of <code>gdb</code>. It does
often work with the <code>cygwin</code> version.</li>
</ul>

<a name="How%20do%20I%20include%20C++%20code%3f"></a> 
<h3>7.5 How do I include C++ code?</h3>

<p>You need to do two things:</p>

<p>(a) Write a wrapper to export the symbols you want to call from
R as <code>extern "C"</code>.</p>

<p>(b) Include the C++ libraries in the link to make the DLL.
Suppose <code>X.cc</code> contains your C++ code, and
<code>X_main.cc</code> is the wrapper, as in the example in
<em>`Writing R Extensions'</em>. Then build the DLL by
(<code>gcc</code>)<br>
</p>

<pre>
...\bin\Rcmd SHLIB X.cc X_main.cc
</pre>

<p>or (VC++, which requires extension <code>.cpp</code>)<br>
</p>

<pre>
cl /MT /c X.cpp X_main.cpp
link /dll /out:X.dll /export:X_main X.obj X_main.obj
</pre>

<p>or (Borland C++, which also requires extension
<code>.cpp</code>)<br>
</p>

<pre>
bcc32 -u- -WDE X.cpp X_main.cpp
</pre>

<p>and call the entry point(s) in <code>X_R</code>, such as
<code>X_main</code>. Construction of static variables will occur
when the DLL is loaded, and destruction when the DLL is unloaded,
usually when R terminates.</p>

<p>Note that you will not see the messages from this example in the
GUI console: see the next section.</p>

<p>This example is in package <code>cxx_0.0-x.tar.gz</code> in the
<code>src/contrib/Devel</code> section on CRAN, and that can be
compiled as a package in the usual way on Windows. <a name=
"The%20output%20from%20my%20C%20code%20disappears."></a></p>

<h3>7.6 The output from my C code disappears. Why?</h3>

<p>The <code>Rgui.exe</code> console is a Windows application:
writing to <code>stdout</code> or <code>stderr</code> will not
produce output in the console. (This will work with
<code>Rterm.exe</code>.) Use <code>Rprintf</code> or
<code>REprintf</code> instead. These are declared in header file
<code>R_ext/PrtUtil.h</code>.</p>

<p>Note that output from the console is delayed (see <a href=
"#The%20output%20to%20the%20console%20seems%20to%20be%20delayed">The
output to the console seems to be delayed</a>), so that you will
not normally see any output before returning to the R prompt. <a
name=
"The%20output%20from%20my%20Fortran%20code%20disappears."></a></p>

<h3>7.7 The output from my Fortran code disappears. Why?</h3>

<p>Writing to Fortran output writes to a file, not the
<code>Rgui</code> console. Use one of the subroutines
<code>dblepr</code>, <code>intpr</code> or <code>realpr</code>
documented in the <em>`Writing R Extensions'</em> manual.</p>

<p>Note that output from the console is delayed (see <a href=
"#The%20output%20to%20the%20console%20seems%20to%20be%20delayed">The
output to the console seems to be delayed</a>), so that you will
not normally see any output before returning to the R prompt even
when using the <code>xxxpr</code> subroutines. <a name=
"The%20console%20freezes%20when%20my%20compiled%20code%20is%20running">
</a></p>

<h3>7.8 The console freezes when my compiled code is running.</h3>

<p>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 <code>R_ProcessEvents()</code> periodically
from your compiled code. If you want output to be updated on the
console, call <code>R_FlushConsole()</code> and then
<code>R_ProcessEvents()</code>.</p>

<hr width="100%">
<address>Last edited 2002 June 01 by Professor B. D. Ripley
<code><a href=
"mailto:ripley@stats.ox.ac.uk">ripley@stats.ox.ac.uk</a></code></address>
</body>
</html>