\input texinfo
@c %**start of header
@setfilename rw-FAQ.info
@settitle R for Windows FAQ
@set VERSION @RWVER@
@set RVERSION @RVER@
@paragraphindent 0
@c %**end of header

@finalout

@include R-defs.texi

@macro newchap{}
@ifinfo
@sp 1
@end ifinfo
@ifhtml
@html
<hr>
@end html
@end ifhtml
@end macro

@titlepage
@title R for Windows FAQ
@subtitle Frequently Asked Questions on R for Windows
@subtitle Version @value{VERSION}
@author B. D. Ripley and D. J. Murdoch, updates by @I{T. Kalibera}
@end titlepage

@ifinfo
R for Windows FAQ                                       @*
Frequently Asked Questions on R for Windows             @*
Version for @value{VERSION}                             @*
B. D. Ripley and D. J. Murdoch, updates by @I{T. Kalibera}  @*

@sp 2
@end ifinfo

@contents

@ifinfo
@sp 1
@end ifinfo

@node Top
@top R for Windows FAQ

@ifhtml
@html
<h2>Version for <kbd>@value{VERSION}</kbd></h2>
<address>B. D. Ripley and D. J. Murdoch, updates by @I{T. Kalibera}</address>
<hr>
@end html
@end ifhtml



@newchap{}
@node Introduction
@chapter Introduction

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

@display
@uref{https://CRAN.R-project.org/doc/FAQ/R-FAQ.html}.
@end display

The information here applies only to recent versions of R for Windows.  It
is biased towards users of 64-bit Windows and since R 4.2.0, only 64-bit
builds of R are provided.  R since version 4.4.0 has experimental native
support for Windows on 64-bit ARM.



@newchap{}
@node Installation and Usage
@chapter Installation and Usage


@node Where can I find the latest version?
@section Where can I find the latest version?

Go to any CRAN site (see @uref{https://CRAN.R-project.org/@/mirrors.html}
for a list), navigate to the @file{bin/windows/base} directory and
collect the file(s) you need.  The current release is distributed as an
installer @samp{@RWVER@-win.exe} of about 80MB.

There are also links on that page to the @samp{r-patched} and
@samp{r-devel} snapshots.  These are frequently updated builds of
development versions of R.  The @samp{r-patched} build includes bug
fixes to the current release, and @samp{r-devel} contains these as well
as changes that are planned to eventually make it into the next
@samp{x.y.0} release. @samp{r-devel} is less stable and likely to contain
bugs, be careful if you use it.


@node How do I install R for Windows?
@section How do I install R for Windows?

Current binary versions of R are known to run on Windows 10 or later. R 4.1
is the last version that supported 32-bit versions: @xref{Can I use R on 64-bit Windows?}.
Windows Vista, 7 and 8 are no longer supported. 

R 4.2.0 and later require the Universal C Runtime (@abbr{UCRT}), which is included in
Windows 10 and Windows Server 2016 or newer. On earlier versions of Windows,
@abbr{UCRT} has to be installed before installing R.  @abbr{UCRT} is available for Windows since
Windows Vista SP2 and Windows Server 2008 SP2. 

@I{Rtools45} requires at least Windows 8.1.  This
requirement comes from @I{Msys2}, so it might still be possible to use build
tools from an older version of @I{Rtools} or @I{Msys2} with the current
toolchain and libraries from @I{Rtools}, but R 4.5.0 is no longer supported
there, anyway.

@c 2000 went end-of-life 2010-07-13
@c XP SP3 went end of life 2014-04-08
@c Vista went end of life 2017-04-11 
@c 7 went end of life 2020-01-14
@c 8 went end of life 2016-01-12, but 8.1 is still supported
@c Server 2008 R2 went end of life 2020-01-14

We primarily test on versions of Windows currently supported by Microsoft,
recently mainly Windows 10, Windows Server 2022 and sometimes on Windows 11. 
The most thorough testing is done via CRAN packages checks: for R 4.3-4.5
this has been on Windows Server 2022.  R 4.3-4.4.0 has been tested to
install, start and pass its own checks also on Windows 7 and Windows 8.1,
but it has not been tested with contributed packages.  Since version 4.5.0,
R is no longer tested on these systems (note @I{MiKTeX} no longer supports them).

For UTF-8 to be the native encoding, you need R at least 4.2 and at least
Windows 10 (version 1903) on desktop systems, Windows Server 2022 on
long-term support server systems or Windows Server 1903 from the semi-annual
channel.

Since version 4.4.0, R has experimental native support for Windows on ARM,
which requires at least Windows 11.  The testing of native builds of R on
Windows on ARM has been limited.  R was tested to install, start and pass
its own checks, but there were no regular CRAN package checks and the number
of installable CRAN packages was lower than on Intel.  One can also install
R for Intel on Windows on ARM and use it via emulation, but numerical
differences have been observed.  The native build on R for Windows on ARM
installs into a different directory by default and uses a different library,
so it can coexist with an installation of the Intel build.

Your file system must allow case-honouring long file names (as is likely
except perhaps for some network-mounted systems).  An installation takes
up to 175MB of disk space.

We tried to make R to work with space in file names, but building of some
packages from source may not work as this is little tested.  By default,
most versions of Windows have short names (aka 8dot3names) enabled by
default on the system drive, and hence @file{Program Files} folder has a
short-name variant @samp{PROGRA~1}, which is then used by R.  When R is
installed on a different drive, we recommend that you ensure that the short
name is available or choose an installation directory name without space,
such as @file{D:\R}.  You can check whether the short name is available from
R by @code{shortPathName(R.home())} or by @command{dir /X} from the
@samp{Command Prompt}.  If it is not, you may create it using
@command{fsutil}, e.g.
@command{fsutil file setshortname "Program Files" PROGRA~1} and
@command{fsutil file setshortname "Program Files (x86)" PROGRA~2}. This may
also be needed by some other applications used from R packages.
We have come across Windows Server 2022 docker container images with short
names disabled even on the system drive.

Installing to
a network share (a filepath starting with @code{\\machine\...}) is not
supported: such paths will need to be mapped to a network drive.

To install use @samp{@RWVER@-win.exe}.  Just double-click on the icon
and follow the instructions.  If you have an account with Administrator
privileges you will be able to install R in the @file{Program Files}
area and to set all the optional registry entries; otherwise you will
only be able to install R in your own file area.  Since R 4.2.0, the default
location in that case is the User Program Files folder (typically
@file{$@{LOCALAPPDATA@}\Programs}, so e.g.
@file{C:\Users\username\AppData\Local\Programs}). Prior to R 4.2.0, the
default location was the Windows "personal" directory  (typically
@file{C:\Users\username\Documents}). Once R is installed, one may open the
installation directory in explorer using @code{shell.exec(R.home())}.

The native build for Windows on ARM uses a different installer.

You may need to
confirm that you want to proceed with installing a program from an
`unknown' or `unidentified' publisher.

After installation you may choose a working directory for R. By default,
it is the Windows "personal" directory  (typically 
@file{C:\Users\username\Documents}). You
will have a shortcut to @file{Rgui.exe} on your desktop and/or somewhere
on the Start menu file tree, and perhaps also in the Quick Launch part
of the taskbar (Vista and earlier).  Right-click each shortcut, select
Properties... and change the `Start in' field to your working directory.
Also, you need to remove the argument @code{--cd-to-userdocs} in the Target
field, which implements the default behavior.
(If your account was not the one used for installation, you may need to
copy the shortcut before editing it.) 

On some systems with R prior to 4.2 you will have two shortcuts, one for
32-bit with a label starting @code{R i386} and one for 64-bit starting
@code{R x64} (@pxref{Should I run 32-bit or 64-bit R?})

You may also want to add command-line arguments at the end of the
Target field (@emph{after} any final double quote, and separated by a
space), for example @code{--sdi --no-environ}.  You can also set
environment variables at the end of the Target field, for example
@code{R_LIBS=p:/myRlib}, and if you want to ensure that menus and
messages are in (American) English, @code{LANGUAGE=en}.

@c It is also possible to install from an MSI file, which will be of
@c interest only for system administrators.  For how to build the MSI file,
@c see the `R Installation and Administration Manual'.


@node How do I check an installation?
@section How do I check an installation is not corrupt?

Relates to earlier installers, removed in R 2.11.0.


@node Can I customize the installation?
@section Can I customize the installation?

The normal way to customize the installation is by selecting components
from the wizards shown by the installer.  However, sysadmins might like
to install R from scripts, and the following command-line flags are
available for use with the installer.

@table @samp
@item /SILENT
only show the installation progress window and error messages.
@item /VERYSILENT
only show error messages.
@item /DIR="x:\dirname"
set the default installation directory
@item /GROUP="folder name"
set the default Start-menu group name
@item /COMPONENTS="comma separated list of component names"
set the initial list of components: Components are named @samp{main},
@samp{i386} (up to R 4.1), @samp{x64} and @samp{translations}.
@item /CURRENTUSER
install for the current user only even if the current user has Administrator
privileges
@end table

@noindent
It is also possible to save the settings used to a file and later
reload those settings using

@table @samp
@item /SAVEINF="filename"
save the settings to the specified file.  Don't forget to use the quotes if
the filename contains spaces.
@item /LOADINF="filename"
instructs the installer to load the settings from the specified file
after having checked the command line.
@end table

A successful installation has exit code 0: unsuccessful ones may give 1,
2, 3, 4 or 5.  See the help for @I{Inno Setup}
(@uref{https://jrsoftware.org/}) for details.

@c We have some facilities for building a customized installer, in
@c particular to add packages to the installer.  See the `R Installation
@c and Administration' manual in the subsection `Building the installers'.


@node How do I run it?
@section How do I run it?

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 a `Command Prompt' or a port of a Unix shell such as
@command{tcsh} or @command{bash}. (The command line can be anything you
would put in the Target field of a shortcut, and the starting directory
will be the current working directory of the shell.  Note that the R
executables are not by default added to the @env{PATH}.)  People running
from a terminal usually prefer to run @command{Rterm.exe} and not
@command{Rgui.exe}.


@node Can I run R from a CD or USB drive?
@section Can I run R from a CD or USB drive?

Yes, with care.  A basic R installation is relocatable, so you can burn
an image of the R installation on your hard disc or install directly
onto a removable storage device such as a flash-memory USB drive.

Running R does need access to a writable temporary directory and to a
home directory, and in the last resort these are taken to be the current
directory.  This should be no problem on a properly configured version
of Windows, but otherwise does mean that it may not be possible to run R
without creating a shortcut starting in a writable folder.


@node How do I UNinstall R?
@section How do I @I{UNinstall} R?

Normally you can do this from the @samp{Programs and Features} group in
the Control Panel.  If it does not appear there, run @file{unins000.exe}
in the top-level installation directory.  On recent versions of Windows
you may be asked to confirm that you wish to run a program from an
`unknown' or `unidentified' publisher.

Uninstalling R only removes files from the initial installation, not
(for example) packages you have installed or updated in your personal
library.

If all else fails, you can just delete the whole directory in which R
was installed.


@node What's the best way to upgrade?
@section What's the best way to upgrade?

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, and then handle
the library.

For those with a personal library (folder @file{R\win-library\@var{x.y}} of
your @file{$@{LOCALAPPDATA@}} directory in R since 4.2.0, or of your home
directory with earlier versions of R), nothing has to be done when the
major and minor version of R (@var{x.y}) stays the same, but it may still be
an opportunity to run @code{update.packages(checkBuilt=TRUE, ask=FALSE)}.

With native build of R on Windows on ARM, the folder name is different, it
includes @file{aarch64-library} instead of @file{win-library}.

When the minor or even major version of R changes, one has to install all
required packages again.  The new version of R will use a different location
for the personal library and the old personal library will be left intact
(it may be deleted manually when no longer needed).  Installed packages
should not be copied from the old library to the new one, because they may
be incompatible with the new version of R.


@node How can I keep workspaces for different projects in different directories?
@section How can I keep workspaces for different projects in different directories?

Create a separate shortcut for each project: see Q2.5.  All the paths to
files used by R are relative to the starting directory, so setting the
`Start in' field (and removing the
@code{--cd-to-userdocs} argument) automatically helps separate projects.

Alternatively, start R by double-clicking on a saved @file{.RData} file
in the directory for the project you want to use, or drag-and-drop a
file with extension @file{.RData} onto an R shortcut.  In either case,
the working directory will be set to that containing the file.


@node How do I print from R?
@section How do I print from R?

It depends what you want to print.

@itemize @bullet
@item
You can print the graphics window from its menu or by using
@code{dev.print} with suitable arguments (see its help page: most likely
@code{dev.print(win.graph)} will work).

@item
You can print from the R console or pager by @samp{File | Print}.
(This will print the selection if there is one, otherwise the whole
console or pager contents.)

@item
You can print help files from the pager or HTML browser.

@item
If you have LaTeX installed and a PDF printing system you
can print help files by @code{help(fn_name, help_type="PDF")}.
@end itemize


@node Can I use R CMD BATCH?
@section Can I use @code{R CMD BATCH}?

Yes: use @code{R CMD BATCH --help} or @code{?BATCH} for full details.

You can also set up a batch file using @command{Rterm.exe}.  A sample
batch file might contain (as one line)

@example
path_to_R\bin\x64\Rterm.exe --no-restore --no-save < %1 > %1.out 2>&1
@end example

Exclude @file{\x64} from the above with native builds of R on ARM.

@noindent
The purpose of @code{2>&1} is to redirect warnings and errors to the
same file as normal output.


@node Can I use @RWVER@ with ESS and Emacs?
@section Can I use @RWVER@ with @I{ESS} and Emacs?

Yes.  @I{ESS} has for a long time supported R under Windows: it does so by
running @code{Rterm.exe} without a visible console.

For help with @I{ESS}, please send email to @email{ESS-help@@stat.ethz.ch},
not the R mailing lists.


@node What are HOME and working directories?
@section What are HOME and working directories?

Several places in the documentation use these terms.

The working directory is the directory from which @code{Rgui} or
@command{Rterm} was launched, unless a shortcut was used when it is given
by the `Start in' field of the shortcut's properties (or @code{--cd-to-userdocs}
was passed as argument). You can find this
from R code by the call @code{getwd()}.

The home directory (sometimes referred to as user's home directory, but not
R home directory) is set as follows: If environment variable
@env{R_USER} is set, its value is used.  Otherwise if environment
variable @env{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
(typically @file{C:\Users\username\Documents}).  If that fails (but that 
is not expected on current Windows), if both
environment variables @env{HOMEDRIVE} and @env{HOMEPATH} are set (and
they normally are), the value is @file{$@{HOMEDRIVE@}$@{HOMEPATH@}}.  If
all of these fail, the current working directory is used.

You can find the home directory from R code by @code{Sys.getenv("R_USER")}
or @code{normalizePath("~")}, @samp{~} being Unix notation for the home
directory. Note that some distributions of Unix utilities for Windows, such
as @I{Msys2} (and hence @I{Rtools}) or @I{Cygwin} set the environment variable
@env{HOME} to a user directory of their choice. When R is invoked from a
shell of such an distribution, the home directory in R would hence
typically not be the Windows "personal" directory. With @I{Rtools40},
@I{Rtools42-44}, it is the user profile (e.g.,
@file{C:\Users\username}). 

The R home directory is the directory where R was installed. You can find
this from R code by @code{R.home()} or @code{Sys.getenv("R_HOME")}. From
outside R, you can find it by invoking @code{R RHOME}.


@node How do I set environment variables?
@section How do I set environment variables?

Environment variables can be set for @command{Rgui.exe} and
@command{Rterm.exe} in three different ways.
@enumerate
@item
On the command line as name=value pairs.  For example in the shortcut to
@command{Rgui} you could have

@example
"path_to_R\bin\x64\Rgui.exe" HOME=p:/ R_LIBS=p:/myRlib
@end example

Exclude @file{\x64} from the above with native builds of R on ARM.

@item
In an environment file @file{.Renviron} in the working directory
or in your home directory, for example containing the line

@example
R_LIBS=p:/myRlib
@end example

If you have permission to do so, you can also create an environment file
@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 @file{.Renviron} file or on the command line.)

See @code{?Startup} for more details of environment files and specifically
pay attention to caveats when using backslashes.

@item
For all applications via Windows.  How you set an environment variable
is system-specific: under recent versions of Windows, go to `User
Accounts' in the Control Panel, and select your account and then `Change
my environment variables'. Or, type `Edit environment variables for your
account'.
@end enumerate

The order of precedence for environmental variables is the order in
which these options are listed, that is the command line then
@file{.Renviron} then the inherited environment.


@node R can't find my file
@section R can't find my file, but I know it is there!

How did you specify it?  Backslashes have to be doubled in R character
strings, so for example one needs
@samp{"d:\\@RWVER@\\library\\xgobi\\scripts\\xgobi.bat"}.  You can make
life easier for yourself by using forward slashes as path separators:
they do work under Windows.  You should include the file extension
(e.g.@: @samp{"xgobi.bat"} rather than just @samp{"xgobi"}); sometimes
this isn't shown in Windows Explorer, but it is necessary in R.

A simple way to avoid these problems is to use the function
@code{file.choose()} to invoke the standard Windows file selection
dialog.  If you select a file there, the name will be passed to R in
the correct format.

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 @samp{PROGRA~1}; you can get it as the
`MS-DOS name' from the Properties of the file on some versions of
Windows, and from @command{dir /X} in a @samp{Command Prompt} window),
and using the function @code{shortPathName} from R code. See also Q2.2.

Yet another complication is a 260 character limit on the length of the
entire path name imposed by Windows.  The limit applies only to some system
functions, and hence it is possible to create a long path using one
application yet inaccessible to another.  It is sometimes possible to
reduce the path length by creating a drive mapping using @command{subst} and
accessing files via that drive.  As of Windows 10 version 1607 and R 4.3,
one can remove this limit via Windows registry by setting
@code{Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled}
to @code{1}.  Long paths still may not always work reliably: some
applications or packages may not be able to work with them and Windows
cannot execute an application with long path as the current directory.


@node Does R use the Registry?
@section Does R use the Registry?

Not when R itself is running.

When you run the R installer, there are options (under @samp{Select
Additional Tasks}) to @samp{Save version number in registry} and (for
Administrator installs) @samp{Associate R with .RData files}.

If you tick the first option, the following string entries are added to the
Windows registry:
@itemize @bullet
@item  @code{HKEY_LOCAL_MACHINE\Software\R-core\R\Current Version}  
    contains the version number, currently @RVER@.
@item @code{HKEY_LOCAL_MACHINE\Software\R-core\R\[version]\InstallPath}
    (where @code{[version]} is currently @RVER@) contains the path to the R 
    home directory.
@end itemize
If you do not have administrative privileges on the machine while
running the installer, then the entries are created under
@code{HKEY_CURRENT_USER}.  The same entries are also created under
@code{Software\R-core\R32} or @code{Software\R-core\R64}, for 32- and
64-bit Intel R builds respectively (only 64-bit since R 4.2).

If you tick the second option (shown with administrative privileges
only) (@samp{Associate R with .RData files}) then entries are created
under @code{HKEY_CLASSES_ROOT\.RData} and
@code{HKEY_CLASSES_ROOT\RWorkspace}.

After installation you can add the Registry entries by running
@code{RSetReg.exe} in a sub-folder of the @code{bin} folder, and remove
them by running this with argument @code{/U}.  Note that this requires
administrative privileges unless run with argument @code{/Personal} and
neither sets up nor removes the file associations.


@node Does R support automation?
@section Does R support automation (OLE, COM)?

Directly, no.  See packages such as @code{RDCOMClient} from Omegahat
(@uref{https://github.com/omegahat/RDCOMClient},
source and binary packages for earlier versions of R available from
@uref{https://www.stats.ox.ac.uk/pub/RWin/})
@c @uref{https://www.omegahat.net/} 
and the non-Free project at @uref{https://www.autstat.com/}.


@node The Internet download functions fail.
@section The Internet download functions fail.

for example @code{update.packages()} and the menu items on the Packages menu.

We have had several reports of this, although they do work for us on
@emph{all} of our machines.  There are two known possible causes.

(a) A proxy needs to be set up: see @code{?download.file}. Note that this is
specific to the download method and the default method changed in R 4.2.0.

(b) Firewall settings are blocking the R executables from contacting the
Internet (but this should result in informative error messages from the
firewall program).

(c) A MITM proxy (typically in enterprise environments) makes it impossible
to validate that certificates haven't been revoked.  One can switch to only
best effort revocation checks via an environment variable: see
@code{?download.file}.


@node Entering certain characters crashes Rgui.
@section Entering certain characters crashes @I{RGui}.

This has not been reported for many years, but used to happen
regularly.  All the occurrences we have solved have been traced to
faulty versions of @samp{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 `@I{JS Pager}'.

R 4.2 and later use @abbr{UCRT} as the C runtime instead of @abbr{MSVCRT}. No such problems have
been reported so far.


@node What does 'DLL attempted to change FPU control word' mean?
@section What does '@I{DLL attempted to change FPU control word}' mean?

This is a @emph{warning} which indicates that R has taken action to
correct the action of some (non-R) DLL which has just been loaded and
has changed the floating point control word (in its initialization code)
to a setting incompatible with that needed for R.  This is not good
practice on the part of the DLL, and often indicates that it needs to be
updated.

Unfortunately, because DLLs may themselves load other DLLs it is not
possible for R to track which DLL caused the problem.

This is less of a problem with 64-bit builds of R, which use SSE
instructions for computations instead of the @abbr{FPU}. We may be able to remove
this handling of the @abbr{FPU} control word in future versions of R.

This handling is specific to Intel processors, it does not apply to native
builds of R on ARM.

See also @code{?dyn.load}.


@node Other strange crashes.
@section Other strange crashes.

Some users have found that @code{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. This hasn't been 
reported for several years. 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, and R
tries hard to correct this before running its own code.)  For example,
one user reported that the virtual screen manager @I{JSP2} caused this
crash. These errors are essentially impossible for us to fix or work around
beyond the measures already taken.  The only solution we know of is for
the user to replace the buggy system component that is causing the
error.


@node Why does R never use more than 50% of my CPU?
@section Why does R never use more than 50% of my CPU?

This is a misreading of Windows' confusing Task Manager.  R's
computation is single-threaded, and so it cannot use more than one CPU.
What the task manager shows is not the usage in CPUs but the usage as a
percentage of the apparent total number of CPUs.  We say `apparent' as
it treats so-called `hyper-threaded' CPUs such as two CPUs per core, and
most modern CPUs have at least two cores.

You can see how many `CPU's are assumed by looking at the number of
graphs of `CPU Usage History' on the `Performance' tab of the Windows
Task manager.

R itself would only use multiple CPUs during parallel installation of
packages, which needs to be selected by user. Some contributed R packages
use multiple CPUs or multiple threads.


@node Does R run under Windows 7?
@section Does R run under Windows 7/8/10/11/Server 2012/2016/2022?

R 4.5 code base still conservatively uses features of Windows 7 and
later only when available, and otherwise falls back to older features, so it
might still run on 7, but this is no longer tested (see Q2.2), and the code
is tuned for newer systems.  Some performance @I{work-arounds} for old Windows
systems past their end of support may be removed, such as a custom memory
allocator removed in R 4.2.

Since 4.2, R uses UTF-8 as the native encoding on recent Windows (see Q2.2).

R on Windows on ARM requires at least Windows 11. 

Earlier versions of Windows had user and Administrator accounts, and
user accounts could be given administrative privileges (by being added to
the local Administrators group) and so write permission over system
areas such as @file{c:\Program Files}.  R would be installed either by
users in their own file space or by an account with administrator
privileges into a system area.  Sysadmins could set policies for user
accounts, and you might for example have needed to be a `Power User' to
install software at all.

Vista and later normally disable the Administrator account and expect
software installation to be done by an account which is in the local
Administrator group with `admin approval mode' turned on.  (The
Administrator account by default has it turned off.)  Unlike (say)
@I{Windows XP}, such accounts do not run programs with full administrator
privileges, and this is where the issues arise.  These OSes have the
concept of `over-the-shoulder' credentials: if you are running without
full administrator privileges and do something which needs them you may
be prompted with one or more security-check dialog boxes, and may be
required to provide administrator credentials or confirm that you really
want to take that action.

Vista and later will report that the R installer has an `unidentified
publisher' or `unknown publisher' and ask if it should be run.  System
administrators can disable installing applications from non-trusted
sources, in which case you will have to persuade them that R is
trustworthy, or digitally sign the R installer yourself, or (unless this
is also disabled) run the installer from a standard account and install
into your own file area.

@c(The same issues apply to the @file{.msi}
@c version of the installer.)

If you install R as a standard user into your own file space and use it
under the same account, there are no known permission issues.

If you use the default Administrator account (without `admin approval
mode' being turned on) and install/update packages (in the system area
or elsewhere), no issues are known.

If you use an account in the local Administrators group in `admin
approval mode' (which is the intended norm under these OSes),
installation will make use of `over-the-shoulder' credentials.  You will
run into problems if you try installing (including updating) packages in
the main R library.  (It would be nice if at that point R could use
over-the-shoulder credentials, but they apply to processes as a whole.
Vista and later disallow creating @code{.dll} files in the system area
without credentials.)  There are several ways around.

@itemize
@item
Run R with Administrator privileges in sessions where you want to
install packages.  (Do so by right-clicking on the R shortcut and
selecting 'Run as Administrator'.)

@item
Transfer ownership of the R installation to the user which installed R.
To do so, use the security tab on the @samp{Properties} of the top-level
R folder and give `Full Control' over this directory to the user (not
just the Administrator group).

@item
Install packages into a different library tree owned by the account used to
install R.

For an installation to be used by a single user, the simplest way is to
make use of a `personal library': @xref{I don't have permission to write
to the R library directory}.

For a site installation, you can create a site-wide library directory
anywhere convenient, and add it to the default package search path for
all users via @env{R_LIBS_SITE} in @file{etc\Renviron.site}.  @xref{What
are HOME and working directories?}.  There is a standard location for a
site library, the @file{site-library} directory in the top-level R
folder (which you would need to create with full control for the R
installation account).  This will be used for installation in preference
to the main library folder if it exists.

This approach will not allow you to update the recommended packages
unless you `Run as administrator': we suggest you use an R session
running under Administrator privileges when updating those.
@end itemize

If you use an account in the local Administrators group in `admin approval
mode', you can still install R for the current user only in your own file
space without using nor being asked for the `over-the-shoulder' credentials.
See Q2.4.

Another issue with Vista was that the standard POSIX ways that R uses
(e.g.@: in @code{file.info} and @code{file.access}) to look at file
permissions no longer worked reliably.  @code{file.access} was re-written
to work with Windows NT-based security and the new version seems much
more reliable with these OSes (but still not 100% correct).

@c On suitably recent hardware Vista and later can prevent the execution of
@c code from data areas via `Data Execution Prevention' (from a tab in
@c System Properties -> Advanced -> Performance), and sysadmins can turn
@c this on for all programs.  R runs correctly with DEP enabled.


@node Quotes don't come out right on the console/terminal/pager
@section Quotes don't come out right on the console/terminal/pager.

R 4.2 and later use UTF-8 as the native encoding on recent Windows (see Q2.2) and
this should make also this previously reported problem disappear.  With
this feature, R automatically uses the 65001 code page (UTF-8).  When using
@code{RTerm} from the @code{Windows Command Prompt} (@file{cmd.exe}) or
@code{Power Shell}, one may have to select a suitable font that has glyphs for the
characters intended, such as @samp{NSimFun} for Asian language).

R may make use of directional quotes that were not always rendered
correctly by Windows: these are used by default only by @code{Rgui} in
suitable locales (not Chinese/Japanese/Korean).

Whether these are used in R output (from functions @code{sQuote} and
@code{dQuote}) is controlled by @code{getOption("useFancyQuotes")} whose
default is @code{FALSE} except for the @code{Rgui} console.  There are
two potential problems with rendering directional quotes.  The first is
with running @code{Rterm}: in European locales the `Windows Command
Prompt' is by default set up to use MS-DOS and not Windows default
encodings: this can be changed via @command{chcp}, with @command{chcp
1252} being appropriate for Western European (including English)
locales.  The other is that the default raster fonts only include
directional single quotes and not directional double quotes (which will
probably be rendered as a filled rectangle). In R 4.2 and later
on recent versions of Windows where UTF-8 is the native encoding,
@command{Rterm} will automatically switch the console codepage to UTF-8.

Directional quotes will also be used in text help which is normally
displayed in R's internal pager: these may not be rendered correctly in
an external pager.  They are also used in HTML help, where most browsers
use fonts which render them correctly.

The font used can affect whether quotes are rendered correctly.  The
default font in the @code{Rgui} console and internal pager is
@code{Courier New}, which has directional quotes on all the systems we
tried.  @code{Lucida Console} which has elegant glyphs for directional
quotes (but seems rather light unless @I{ClearType} is in use):
@code{Consolas} is another font which we often select when @I{ClearType} is
in use.  Non-@I{TrueType} fonts such as @code{Courier} and @code{FixedSys}
lack directional double quotes on the systems we tried.

There is a related problem with using @code{Sweave} output in
@code{Rgui}, for LaTeX needs to be told about the encoding of
directional quotes by including in the LaTeX preamble e.g.@: (for a
Western European locale)

@example
\usepackage[cp1252]@{inputenc@}
@end example

@noindent
or their use suppressed by @code{options(useFancyQuotes=FALSE)}.


@node There is no tilde on my keyboard
@section There is no tilde on my keyboard!

Where tilde does not appear on the main keyboard, it can normally be
accessed by pressing @key{AltGr} (the right @key{Alt} key) plus some other key.
This is @code{]} in Canadian (multilingual), German and Scandinavian
layouts, @code{1} in Eastern Europe, @code{[} in Portuguese, @code{4} or
@code{5} in Spanish, @code{/} in Francophone Belgian, and so on.  You
can explore those for your keyboard via the `On-Screen Keyboard' (under
Ease of access on Windows 7).

On all Windows versions you should be able to get tilde by holding the
down the left Alt key and typing 0126 on the numeric keypad (if you have
one), then releasing the Alt key.


@node Can I use R on 64-bit Windows?
@section Can I use R on 64-bit Windows?

Yes, and this is the primarily used and the only tested option now.  Since R
4.2.0, 32-bit builds are no longer provided.

The 32-bit build of R for Windows (R 4.1 and earlier) will run on both 32-bit and
64-bit@footnote{what Windows calls x64 for x86-64 CPUs, not the very
rare @I{ia64} Windows for @I{Itanium} CPUs.} versions of Windows.  64-bit
versions of Windows run 32-bit executables under the WOW (Windows on
Windows) subsystem: they run in almost exactly the same way as on a
32-bit version of Windows, except that the address limit for the R
process is 4GB (rather than 2GB or perhaps 3GB).

When R 4.1 and earlier is installed on 64-bit Windows there is the option of installing
32- and/or 64-bit builds: the default is to install both. If you are
using the 32-bit build, replace @samp{x64} by @samp{i386} in the
examples in this FAQ.


@node Should I run 32-bit or 64-bit R?
@section Should I run 32-bit or 64-bit R?

Since R 4.2.0, 32-bit builds are no longer provided.  With older versions of
R, this question is only relevant if you are using 64-bit Windows.

For most users we would recommend using the `native' build, that is the
32-bit version on 32-bit Windows and the 64-bit version of 64-bit Windows.

The advantage of a native 64-bit application is that it gets a 64-bit
address space and hence can address far more than 4GB (how much depends
on the version of Windows, but in principle 8TB).  This allows a single
process to take advantage of more than 4GB of RAM (if available) and for
R's memory manager to more easily handle large objects (in particular
those of 1GB or more).  The disadvantages are that all the pointers are
8 rather than 4 bytes and so small objects are larger and more data has
to be moved around, and that less external software is (was) available for
64-bit versions of the OS. The 64-bit compilers are able to take
advantage of extra features of all x86-64 chips (more registers, SSE2/3
instructions, @dots{}) and so the code may run faster despite using
larger pointers.  The 64-bit build is nowadays usually slightly faster
than the 32-bit build on a recent CPU (Intel Core 2 or later or AMD
equivalent).

For advanced users the choice may be dictated by whether the contributed
packages needed are available in 64-bit builds (although CRAN only
offers 32/64-bit builds).  The considerations can be more complex: for
example 32/64-bit @code{RODBC} need 32/64-bit @abbr{ODBC} drivers respectively,
and where both exist they may not be able to be installed together.  An
extreme example is the Microsoft Access/Excel @abbr{ODBC} drivers: if you have
installed 64-bit Microsoft Office you can only install the 64-bit
drivers and so need to use 64-bit @code{RODBC} and hence R.  (And
similarly for 32-bit Microsoft Office.)


@node Can both 32- and 64-bit R be installed on the same machine?
@section Can both 32- and 64-bit R be installed on the same machine?

Since R 4.2.0, 32-bit builds are no longer provided.

With older version of R, this question is only relevant if the machine is running a 64-bit version of
Windows -- simply select both when using the installer.  You can also go
back and add 64-bit components to a 32-bit install, or @emph{vice versa}.

For many Registry items, 32- and 64-bit programs have different views of
the Registry, but clashes can occur.  The most obvious problem is the
file association for @file{.RData} files, which will use the last
installation for which this option is selected, and if that was for an
installation of both, will use 64-bit R.  To change the association the
safest way is to edit the Registry entry
@samp{HKEY_CLASSES_ROOT\RWorkspace\shell\open\command}
and replace @samp{x64} by @samp{i386} or @emph{vice versa}.


@node Rcmd is not found in my PATH!
@section @I{Rcmd} is not found in my PATH!

This has often been reported after an upgrade.

The R installer does not put @command{Rcmd.exe} (nor any other R
executable) on your @env{PATH}.  What seems to have happened is that
people did this for themselves in the past, upgraded R (which by default
will install to a different location) and @I{un-installed} the old version
of R.  If you do that (or install R for the first time), you need to
edit the @env{PATH}.

The element you want to add to the path is something like

@example
c:\Program Files\R\R-4.5.0\bin\x64
@end example

@noindent
for 64-bit @command{Rcmd.exe}, replacing @code{x64} by @code{i386} for
32-bit, removing @code{x64} for native build on ARM.

How you set the path depends on your OS version.  Under recent versions,
go to `User Accounts' in the Control Panel, and select your account and
then `Change my environment variables'.  (System policies can prevent
end users making changes.)

An alternative is to set the @env{PATH} in the shell you are running
(@command{Rcmd.exe} is  a command-line program).  For those using the
standard Windows `Command Prompt' Duncan Murdoch suggested:
@c https://stat.ethz.ch/pipermail/r-help/2011-October/293413.html

The simple way to do it just for the command prompt is to write a little 
batch file @command{setpath.bat} containing

@example
set PATH=newstuff;%PATH%
@end example

@noindent
and then run @command{cmd} with

@example
CMD /K setpath.bat
@end example



@newchap{}
@node Languages and Internationalization
@chapter Languages and Internationalization


@node The installer does not offer my language
@section The installer does not offer my language.

Only a limited range of languages is supported, currently
Catalan,
both Simplified and Traditional Chinese,
Czech,
Danish,
Dutch,
Finnish,
French,
German,
Greek,
Hebrew,
Hungarian,
Italian,
Japanese,
Korean,
Norwegian,
Polish,
Portuguese (Brazil),
Portuguese (Portugal),
Russian,
Slovenian,
Spanish (Spain)
and Ukrainian.


@node I want R in English!
@section I want R in English (and not in French/Chinese/...)!

The default behaviour of R is to try to run in the language you run
Windows in.

Apparently some users want@footnote{or they may have no choice:
apparently some Windows editions are tied to a specific language.}
Windows in their native language, but not R.  To do so, set
@code{LANGUAGE=en} as discussed in Q2.2 and Q2.15, or in the
@file{Rconsole} file.


@node I want to run R in Chinese/Japanese/Korean
@section I want to run R in Chinese/Japanese/Korean.

Suitable versions of Windows support what it calls `East Asian'
languages, but e.g.@: Western installations of Windows often do not have
such support.  So we need to assume that your copy of Windows does.

R 4.2 and later on recent versions of Windows (see Q2.2) use UTF-8 as the native
encoding.  It is thus possible to use characters outside of the system
locale code page in R, including the command-line front-end
@command{Rterm.exe} (and @command{Rgui.exe}, where limited support has
existed before). For use in @command{RTerm}, one needs to choose suitable fonts
which have the required glyphs, such as @code{NSimFun} for Asian languages.
Use @code{l10n_info()} from R to check whether R is really running in UTF-8
as native encoding.

With R 4.2 and later on earlier versions of Windows and with earlier versions of R,
the following content still applies.

Both @command{Rterm.exe} and @command{Rgui.exe} support single- and
double-width characters.  It will be necessary to select suitable fonts
in files @file{Rconsole} and @file{Rdevga} (see @code{?Rconsole} or the
comments in the files: the system versions are in the @file{etc}
folder); in the latter you can replace @code{Arial} by @code{Arial
Unicode MS}, and we tried @code{FixedSys} and @code{MS Mincho} in
@file{Rconsole}.  (Note that @file{Rdevga} only applies to Windows
graphics devices and not, say, to @code{pdf}.)  

Note that it is important that the console font uses double-width
characters for all CJK characters (as that is what the width table used
assumes): this is true for the fonts intended for CJK locales but not
for example for @code{Lucida Console} or @code{Consolas}.

You do need to ensure that R is running in a suitable locale: use
@code{Sys.getlocale()} to find out.  (CJK users may be used to their
language characters always being available, which is the case for
so-called `Unicode' Windows applications.  However, R is primarily
written for Unix-alikes and is not therefore `Unicode' in the Windows
sense.)  You can find suitable locale names from
@uref{https://msdn.microsoft.com/@/en-us/@/library/@/39cwe7zf%28v=vs.80%29.aspx}
and @uref{https://msdn.microsoft.com/@/en-us/@/library/cdax410z%28v=vs.80%29.aspx}
beware that @code{"Chinese"} is Traditional Chinese (code page 950,
Big5) and @code{"chs"} is needed for Simplified Chinese (code page 936,
GB2312).

When using @command{Rterm} the window in which it is run has to be set
up to use a suitable font (e.g. @code{Lucida Console} or
@code{Consolas}, not the @abbr{OEM} raster fonts) and a suitable codepage
(which for the Windows command shell can be done using @command{chcp}). In R 4.2
and later on recent versions of Windows where UTF-8 is the native encoding,
@command{Rterm} will automatically switch the console codepage to UTF-8.


@node I selected English for installation but R runs in Chinese
@section I selected English for installation but R runs in Chinese.

Precisely, you selected English @strong{for installation}!  The language
of the installer has nothing to do with the language used to run R: this
is completely standard Windows practice (and necessary as different
users of the computer may use different languages).

The language R uses for menus and messages is determined by the
@emph{locale}: please read the appropriate manual
(@ref{, , , R-admin, R Installation and Administration})
for the details.  You can ensure that R uses English
messages by appending @code{LANGUAGE=en} to the shortcut you use to
start R, or setting it in the @file{Rconsole} file.


@node I would like to be able to use Japanese fonts
@section I would like to be able to use Japanese fonts.

for example, in the console and to annotate graphs.  Similar comments
apply to any non-Western-European language.

With suitable fonts, this should just work.  You will need to set @I{MS
Mincho} or MS Gothic as the console font to ensure that single- and
double-width characters are handled correctly.  The default graphics
fonts for the @code{windows()} graphics device can handle most common
Japanese characters, but more specialized fonts may need to be set.
(See Q5.2 for how to set fonts: the console font can also be set from
the `GUI preferences' menu item.)  The help for @code{windowsFonts} has
examples of selecting Japanese fonts for the @code{windows()} family of
devices.

In addition, the Hershey vector fonts (see @code{?Hershey},
@code{?Japanese} and @code{demo(Japanese)}) can be used on any graphics
device to display Japanese characters.

To use non-Latin-1 characters in the @code{postscript} graphics device,
see its help page (which also applies to @code{pdf}).


@node I don't see characters with accents at the R console
@section I don't see characters with accents at the R console, for example in ?text.

You need to specify a font in @file{Rconsole} (see Q5.2) that supports
the encoding in use.  This used to be a problem in earlier versions of
Windows, but now it is hard to find a font which does not.

Support for these characters within @command{Rterm} depends on the
environment (the terminal window and shell, including locale and
codepage settings) within which it is run as well as the font used by
the terminal window.  Those are usually on legacy DOS settings and need
to altered (see Q3.3).


@node The dialog buttons are not translated
@section The dialog buttons are not translated.

In most cases they actually are, but by Windows.  Setting the locale or
the @code{LANGUAGE} environment variable does not change the Windows
setting of its `@I{UI language}'.  Vista and later talk about the '@I{UI
language}' and the 'system locale' for setting the language used for
`non-Unicode' programs (on the 'Administrative' tab in Windows 7).

If you have Windows running completely in say French or Chinese these
settings are likely to be consistent.  However, if you try to run
Windows in one language and R in another, you may find the way Windows
handles internationalization slightly odd.
@c For further details see
@c @uref{http://msdn.microsoft.com/@/library/@/default.asp?url=/@/library/@/en-us/@/intl/@/nls_0ddl.asp}.



@newchap{}
@node Packages
@chapter Packages


@node Can I install packages into libraries in this version?
@section Can I install packages into libraries in this version?

Yes, but you will need a lot of tools to do so, unless the author or the
maintainers of the @file{bin/windows/contrib} section on CRAN have been
kind enough to provide a binary version for Windows as a
@code{.zip} file, or the package is a simple one involving no compiled
code (and binary versions are usually available for simple
packages).

You can install binary packages either from a repository such as
CRAN or from a local @code{.zip} file by using @code{install.packages}:
see its help page.  There are menu items on the @code{Packages} menu to
provide a point-and-click interface to package installation.  The
packages for each minor (4.x.?) version will be stored in a separate area,
so for R 4.5.? the files are in @file{bin/windows/contrib/4.5}.

@c Note that the binary versions on CRAN are unsupported: see
@c @uref{https://CRAN.R-project.org/@/bin/@/windows/@/contrib/@/4.3/@/ReadMe},
@c which also gives the locations of a few other binary packages.

If there is no binary package or that is not up-to-date or you prefer
compiling from source,
@pxref{Add-on packages, , , R-admin, R Installation and Administration}.
Source packages which contain no
C/C++/Fortran code which needs compilation can simply be installed by
@code{install.packages(type = "source")} or @command{R CMD INSTALL
@var{pkgname}} at a Windows command prompt.  For packages with code that needs
compilation you will need to collect and install several tools: you can
download them via the portal at
@uref{https://CRAN.R-project.org/bin/windows/Rtools/} and check for more
detailed instructions there. Once you have done
so, just run @command{R CMD INSTALL @var{pkgname}} at a Windows command
prompt.  To check the package (including running all the examples on its
help pages and in its test suite, if any) use @command{R CMD check
@var{pkgname}}:
@pxref{Checking and building packages, , , R-exts, Writing R Extensions}.

Note that setting up Windows to install a source package that needs
compilation is rather tricky; please do ensure that you have followed
the instructions @strong{exactly}.  At least 90% of the questions asked
are because people have not done so.

If you have a source package that is known to work on a Unix-alike
system, you can try the automated Windows binary package builder
documented at @url{https://win-builder.R-project.org}.

The native (default) builds of R 4.5.0 for Windows on ARM only install
packages from source. This may be changed in the future.


@node I don't have permission to write to the R library directory
@section I don't have permission to write to the R @file{library} directory.

You can install packages anywhere and use the environment variable
@env{R_LIBS} (@pxref{How do I set environment variables?}) to point to
the library location(s).

Suppose your packages are installed in @file{p:\myRlib}.  Then you can
EITHER

@example
set the environment variable R_LIBS to p:/myRlib before starting R
@end example

OR use a package by, e.g.@:

@example
library(mypkg, lib.loc="p:/myRlib")
@end example

You can also have a personal library, which defaults to the directory
@file{R\win-library\@var{x.y}} of your @file{$@{LOCALAPPDATA@}} directory
(e.g. @file{C:\Users\username\AppData\Local}) for versions
@var{x.y.z} since R 4.2.0. With native build of R on ARM, the name includes
@file{aarch64-library} instead of @file{win-library}. With older versions of R, it was a subdirectory
of your home directory by default. This location can be changed by setting the
environment variable @env{R_LIBS_USER}, and can be found from inside R
by running @code{Sys.getenv("R_LIBS_USER")}.  This will only be used if
it exists so you may need to create it: you can use

@example
dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE)
@end example

@noindent
to do so.  If you use @code{install.packages} and do not have permission
to write to the main or site library, it should offer to create a personal
library for you and install the packages there.  This will also happen
if @code{update.packages} offers to update packages for you in a library
where you do not have write permission.

There can be additional security issues under Windows Vista and later:
@xref{Does R run under Windows 7?}.

@c In particular, the detection
@c that a standard user has suitable permissions appears to be unreliable
@c under Vista, so we recommend that you do create a personal directory
@c yourself.


@node The packages I installed do not appear in the HTML help system
@section The packages I installed do not appear in the HTML help system.

This question applied to the pre-2.10.0 HTML help system, which has been
replaced.


@node My functions are not found by the HTML help search system.
@section My functions are not found by the HTML help search system.

This question applied to the pre-2.10.0 search system, which has been
replaced.


@node Loading a package fails.
@section Loading a package fails.

Is the package installed for this version of R?   Packages need to have
prepared for R 4.2.0 or later.

You can tell the version the package was compiled for by looking at the
@samp{Built:} line in its @file{DESCRIPTION} file.

For a small number of binary packages you need to install additional
software and have its DLLs in your @code{PATH}.  Windows will normally
give an informative message about a certain DLL not being found. See
@uref{https://CRAN.R-project.org/@/bin/@/windows/@/contrib/@/4.5/@/ReadMe} for a
listing of some of these packages (notably @code{RGtk2}, @code{cairoDevice},
@code{rggobi}, @code{rJava}, @code{rjags} and some of the packages connecting to databases).


@node Package TclTk does not work.
@section Package @I{TclTk} does not work.

For package @code{tcltk} to work (try @code{demo(tkdensity)} or
@code{demo(tkttest)} after @code{library(tcltk)}) you need to have Tcl/Tk
installed.  This is part of the R installation, so it should be there.

However, if you have the environment variable @env{MY_TCLTK} set to a
non-empty value, it is assumed that you want to use a different Tcl/Tk
8.6.x installation with the path to its @file{bin} directory given by
value of @env{MY_TCLTK}, and that this is set up correctly (with
@env{TCL_LIBRARY} set if needed).  Note that you do need 8.6.x and not
8.5.x nor 8.4.x, and you do need the architecture to match, that is a
32-bit or 64-bit build of Tcl/Tk to match the R build in use.  (There is
no guarantee that a 64-bit build will work: it depends on the layout it
uses and R 4.2 and later use a different layout from previous versions.)

In the past several package authors have suggested using @I{ActiveTcl}
(@uref{https://www.activestate.com/@/Products/@/activetcl/}) as a way to
get Tcl/Tk extensions (but the support files do contain the most
commonly used @code{TkTable} and @code{BWidget} extensions).  This could
be used by setting (for a default install)

@example
MY_TCLTK=c:/Tcl/bin
@end example

@noindent
@strong{but} current versions do not by default contain any extra
extensions (although they may be downloaded via the @code{Teacup}
facility) and this only worked for 32-bit R.

As only 64-bit builds are provided as of R 4.2, the Tcl/Tk bundle used is
now also 64-bit only.  The older combined 32-bit/64-bit bundle for R 4.1
cannot be used with R 4.2 and later, because it has a different directory layout even
for the 64-bit part.


@node  Hyperlinks in HTML do not work.
@section Hyperlinks in HTML sometimes do not work.

This question was much more relevant prior to version 2.10.0.

They may still not work between packages installed in different libraries
if the HTTP server has been disabled: the remedy is not to do that!


@node update.packages() fails
@section @code{update.packages()} fails.

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()}
(or the menu equivalent) in a new session.

If you put @code{library(foo)} in your @file{.Rprofile} you will need to
start R with @option{--vanilla} to be able to update package @code{foo}.
If you set @env{R_DEFAULT_PACKAGES} to include @code{foo}, you will
need to unset it temporarily.

It has been reported that some other software has interfered with the
installation process by preventing the renaming of temporary files,
@emph{Google Desktop} being a known example.


@node How do I add to the list of repositories?
@section How do I add to the list of repositories?

as shown in the @code{Select repositories...} item on the
@code{Packages} menu?

This reads from the tab-delimited file @file{R_HOME\etc\repositories},
which you can edit, or put a modified copy at @file{.R\repositories}
in your HOME directory (@pxref{What are HOME and working directories?}).


@node Help is not shown for some of the packages
@section Help is not shown for some of the packages

This was about Compiled HTML help, which has not been supported since R
2.10.0.


@node How do I get static HTML pages?
@section How do I get static HTML pages?

We presume you want to do this for some special purpose: R's help system
will not make use of them, links across library directories will not
work (unlike R < 2.10.0), ambiguous links will be resolved at install
time and missing links will be broken (previous versions used
JavaScript to look for them at run time).  But if you still want them,
here is how to do it.

Static HTML pages are not part of the binary distribution, so you will
need to install R and/or packages from their sources.  To install just a
few packages with static HTML pages use

@example
R CMD INSTALL --html @var{pkg1} @var{pkg2} @dots{}
@end example

To install R itself with static HTML pages you need to build it from the
sources for yourself.  Change the following line in file
@file{MkRules.local} (after copying @file{MkRules.dist} to
@file{MkRules.local} if that has not already been done).

@example
# set this to YES to build static HTML help
BUILD_HTML = NO
@end example

@noindent
and them all packages installed by that build of R will (by default) be
installed with static HTML pages.


@node How can I get a binary version of a package?
@section How can I get a binary version of a package?

Presumably one not available on CRAN, @abbr{BioC} or a similar repository.

If you have a source package that is known to work on a Unix-alike
system, you can try the automated Windows binary package builder
documented at @url{https://win-builder.R-project.org}.  If the package is
not yours, please remember to change the maintainer address so the
results go to you and not the author(s)!

However, if a CRAN package is not available in binary form, this usually
means that there is a problem with some dependent package or external
software (often mentioned in the @file{@@ReadMe} file in the binary
repository directory).  You can email @email{R-windows@@R-project.org}
expressing a wish for such a package to be ported---the maintainers will
take such wishes into account when prioritizing work on binary packages.

In many cases installing packages from the sources is not at all
difficult (it is simple if the package contains no compiled code), so
please attempt that for yourself before requesting help from the busy
volunteers. See also Q4.1.


@node Package xxx is out of date for Windows
@section Package xxx is out of date for Windows

Here are three possible reasons:

You are simply impatient, and need to wait until the binary package has
been built and propagated to the CRAN mirror you are using.  This
normally (but not always) happens within 24 hours.  Sometimes mirrors do
get behind, so you could try another mirror.

The latest version of the package might require a later version of R
than the one you are using.  You can check on the package's HTML page on
CRAN, and update your R if needed.

Your R might be too old.  Binary packages for the 3.6 series were
built until Apr 2021, and were discontinued for earlier versions by
early 2020.  Packages for R 4.x are built (if possible) whilst 4.(x+1)
is current, but building stops once 4.(x+2) reaches alpha (pre-release,
about a month before release).  You can always try installing from the
sources.


@node No binary packages appear to be available for my version of R
@section No binary packages appear to be available for my version of R

How old is it?  The CRAN policy is to archive binary packages two years
after the 3.x or 4.x series is closed.  Other repositories may do so
sooner.

If you are using an R version that old we advise you to update your R,
but you do also have the option of installing packages from their
source.


@node How do I build my package for both 32- and 64-bit R?
@section How do I build my package for both 32- and 64-bit R?

Since R 4.2.0, 32-bit builds are no longer provided. The following
information refers to previous versions of R.

Packages without compiled code nor a @file{configure.win} script will
run on both 32- and 64-bit R.

Packages with compiled code but no @file{configure.win} nor
@code{src/Makefile.win} file will be built for both when running on a
64-bit version of Windows if both versions of R are installed.

An empty @file{configure.win} is treated in the same way as if none
existed.  Also, there is a list of packages known to have an
architecture-independent @file{configure.win} hardcoded into @command{R
CMD INSTALL}, and for these packages, both architectures will be built
under the above conditions.  Other packages can be installed with
@file{configure.win} run for just the first architecture by using option
@option{--force-biarch}. 

Any package can be installed for first one architecture and then the
other with option @option{--merge-multiarch}, but the package source
must be a tarball (and as before, running on a 64-bit version of Windows
with both versions of R installed).

Finally, a package without a @code{src/Makefile.win} file and no or
empty or architecture-independent @code{configure.win} file can be
installed for both architectures from 32-bit Windows if the 64-bit
components were selected when R was installed and option
@option{--compile-both} is given.  Obviously, only the 32-bit
installation can be tested.



@newchap{}
@node Windows Features
@chapter Windows Features


@node  What should I expect to behave differently from the Unix version
@section  What should I expect to behave differently from the Unix version of R?

@itemize @bullet
@item
R commands can be interrupted by @key{Esc} in @command{Rgui.exe}
and @kbd{Ctrl-break} or @kbd{Ctrl-C} in @command{Rterm.exe}:
@kbd{Ctrl-C} is used for copying in @command{Rgui.exe}.

@item 
Command-line editing is always available, but is somewhat simpler than the
@I{readline}-based editing on Unix.  For @command{Rgui.exe}, the menu item
`Help | Console' will give details.  For @command{Rterm.exe} see file
@file{README.rterm}.

@item Paths to files (e.g.@: in @code{source()}) can be specified with
either "/" or "\\".

@item @code{system()} is slightly different: see its help page and that
of @code{shell()}.
@end itemize


@node I hear about some nifty features.
@section I hear about some nifty features: please tell me about them!

You have read the file @file{README.@RWVER@}? 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{jpeg},
@code{bmp}, @code{postscript}, @code{PDF} or @code{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 @code{options(width=)} is automatically
set to the console width (unless disabled in the configuration file).

The graphics has a history mechanism.  As @file{README.@RWVER@} says:

@quotation
`The History menu allows the recording of plots.  When plots have been
recorded they can be reviewed by @key{PgUp} and @key{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 @key{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 @strong{not} be used as a permanent
  storage format for R plots.

There is only one graphics history shared by all the windows devices.'
@end quotation

@noindent
The R console and graphics windows have configuration files stored in
the @file{RHOME\etc} directory called @file{Rconsole} and @file{Rdevga};
you can keep personal copies in your @file{HOME} directory.  They contain
comments which should suffice for you to edit them to your
preferences.  For more details see @code{?Rconsole}.
There is a GUI preferences editor invoked from the @code{Edit} menu which
can be used to edit the file @file{Rconsole}.


@node Circles appear as ovals on screen
@section Circles appear as ovals on screen.

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 monitor which allows them to be
adjusted.  You can specify correct values either in the call to
@code{windows} or as options: see @code{?windows}.  (Typically these are
of the order of 100.)

On one of our systems, the screen height was 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 was a 21" monitor and 400mm x 300mm!

This is less common with LCD screens but not unknown, particularly if
they are not running at their native resolution.


@node How do I move focus to a graphics window or the console?
@section How do I move focus to a graphics window or the console?

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

This works for @command{Rgui.exe} in MDI and SDI modes, and can be used for
graphics windows from @command{Rterm.exe} (although Windows may not always
act on it).


@node What does TAB completion do?
@section What does TAB completion do?

Both @command{Rgui} and @command{Rterm} support @key{TAB} completion.
Hitting @key{TAB} whilst entering a command line completes the current
`word' as far as is unambiguously possible.  Hitting @key{TAB} a second
time then shows a list of possible completions (or the first few if
there are many): the user can then enter one or more characters and hit
@key{TAB} again.

What is it `completing'?  There are two modes: within an unterminated
(single- or double-) quoted expression it completes file
paths.@footnote{It does not have a complete understanding of Windows
file paths, but can complete most relative or absolute file paths,
including drives and spaces. Relative paths on drives are not handled,
for example.}  Otherwise, it is completing R expressions: most obviously
it will match visible R object names and keywords, so @kbd{apr} followed
by @key{TAB} will (in a vanilla session) complete to @code{apropos}.
After a function name and parenthesis (e.g.@: @kbd{apropos(}) it will
complete argument names (and @kbd{=}), and after @kbd{$} or @kbd{@@} it
will complete list components or slot names respectively.

This feature can be turned off: @command{Rgui} has two menu items to do
so, and setting the environment variable @env{R_COMPLETION} to
@code{FALSE} turns it off completely for both @command{Rgui} and
@command{Rterm}.  Further, the behaviour can be fine-tuned: to see the
settings available use

@example
?rc.settings
@end example

@noindent
which also explains how the various types of completion work.

This feature is very similar to the completion available in the
@code{readline}-based command line interface on Unix-alikes: the macOS
GUI @code{R.app} has a different completion scheme.



@newchap{}
@node Workspaces
@chapter Workspaces


@node My workspace gets saved in a strange place.  How do I stop this?
@section My workspace gets saved in a strange place: how do I stop this?

Have you changed the working directory?: see Q6.2.


@node How do I store my workspace in a different place?
@section How do I store my workspace in a different place?

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
function @code{setwd}: see its help page.


@node Can I load workspaces saved under Unix/GNU-Linux or macOS?
@section Can I load workspaces saved under Unix/GNU-Linux or Mac macOS?

Yes.  All ports of R use the same format for saved workspaces, so they
are interchangeable (for the same 4.x.? version of R, at least).

It is possible to save references to package namespaces when saving the
workspace: if that happens the package will need to be installed on the
machine loading the workspace.

As of R 3.6, which uses serialization format 3 for saving the workspace by
default, information about the current encoding is recorded in the
workspace.

Note though that character data in a workspace will be in a particular
encoding that may not be recorded in the workspace for older versions of R, so workspaces
containing non-@acronym{ASCII} character data may not be interchangeable
even on the same OS.  Since R marks character data when it knows it to
be in UTF-8 or Latin-1 (including its Windows superset, CP1252), strings
in those encodings are likely to be transferred correctly: fortunately
this covers most of the common cases (macOS normally uses UTF-8, and
Linux users are likely to use UTF-8 or perhaps Latin-1).

As of R 3.6, when the workspace is loaded, the characters in other encodings
are converted to the current encoding, if possible. When this is not
possible, such as the characters are not representable in such encodings,
they are converted to UTF-8 with a warning, which may cause some disruption
or confuse some software.

As of R 4.2, when running on recent Windows, the native encoding is UTF-8
and so these problems should disappear.



@newchap{}
@node The R Console
@chapter The R Console


@node The output to the console seems to be delayed
@section When using @I{RGui} the output to the console seems to be delayed.

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: @kbd{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 @code{flush.console()} will write out
the buffer and so update the console.


@node Long lines seem to be truncated.
@section Long lines in the console or pager are truncated.

They only @strong{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 @kbd{@key{CTRL} + left/right arrow} keys to scroll
horizontally. (The @key{left/right arrow} keys work in the pager too.)



@newchap{}
@node Building from Source
@chapter Building from Source


@node How can I compile R from source?
@section How can I compile R from source?

@xref{, , , R-admin, R Installation and Administration}
(for the version of R you want to install).


@node Can I use a fast BLAS?
@section  Can I use a fast BLAS?

Fast BLAS (Basic Linear Algebra Subprograms,
@uref{https://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
(@uref{https://math-atlas.sourceforge.net}).  The savings can be
appreciable but because ATLAS is tuned to a particular chip we can't use
it generally.  However, linear algebra on large matrices is not often an
important part of R computations, and more typical calculations on small
matrices may run slower.

BLAS support is supplied by the single DLL
@file{R_HOME\bin\x64\Rblas.dll}, and you can add a fast BLAS just by
replacing that.
@c Replacements for 32-bit R and some of the older common
@c chips are available on CRAN in directory
@c @file{bin/windows/contrib/ATLAS}.
@xref{, , , R-admin, R Installation and Administration}
for how to build an ATLAS @file{Rblas.dll} tuned
to your system using the R sources.  Unfortunately the process has been
less successful when tried for the common current CPUs.

With a native build of R on ARM, exclude @file{\x64} from the above.

@c Versions of Dr Kazushige Goto's BLAS (see
@c @uref{https://en.wikipedia.org/wiki/Kazushige_Goto}) for 64-bit Windows
@c by Ei-Ji Nakama can be found at
@c @uref{https://prs.ism.ac.jp/~nakama/SurviveGotoBLAS2/binary/windows/x64/}.
@c Just download the file @file{Rblas.dll} appropriate to your CPU and
@c replace @file{@var{R_HOME}/bin/x64/Rblas.dll}.  (There is also a generic
@c version called @samp{DYNAMIC_ARCH} that tries to adapt itself to the CPU
@c found -- however if you know the exact CPU used it is better to download
@c the CPU-specific version.  Note that development of that BLAS was frozen
@c in 2010 so you will not find versions for recent CPUs.)

Note that fast BLAS implementations may give different (and often
slightly less accurate) results than the reference BLAS included in R.


@node  How do I include compiled C code?
@section How do I include compiled C code?

We strongly encourage you to do this @emph{via} building an R package:
@pxref{, , , R-exts, Writing R Extensions}.
In any event you should
get and install the tools and toolchain mentioned in
@ref{, , , R-admin, R Installation and Administration}.
Then you can use
@example
...\bin\x64\R CMD SHLIB foo.c bar.f
@end example
@noindent
to make @file{foo.dll}.  Use @command{...\bin\x64\R CMD SHLIB --help} for
further options, or see @code{?SHLIB}. 
With a native build of R on ARM, exclude @file{\x64} from the above.

@c If you want to use Visual C++, Borland C++ or other compilers, see the
@c appropriate section in @file{README.packages}.


@node How do I debug code that I have compiled and dyn.load-ed?
@section How do I debug code that I have compiled and @code{dyn.load}-ed?

@c Debugging under Windows is often a fraught process, and sometimes does
@c not work at all.  If all you need is a @emph{just-in-time} debugger to
@c catch crashes, consider (32-bit) @code{Dr. Mingw} from the
@c @code{mingw-utils} bundle on @uref{https://www.mingw.org}.  That will be
@c able to pinpoint the error, most effectively if you build a version of R
@c with debugging information as described below.

First, build a version of the R system with debugging information by

@example
make clean
make DEBUG=T
@end example

@noindent
and make a debug version of your package by

@example
Rcmd INSTALL --debug mypkg
@end example

@noindent
@xref{, , , R-admin, R Installation and Administration}
(for the version of R you
want to install) and @uref{https://CRAN.R-project.org/bin/windows/Rtools/}
for links to detailed information on how to build R and R packages from
source using corresponding versions of @I{Rtools} and for additional hints for
debugging on Windows, including how to debug a native build of R on ARM. The
description here only covers Intel builds of R.

You will need a suitable version of @command{gdb} which matches your
compiler.  Then you can debug by

@example
gdb /path/to/@RWVER@/bin/x64/Rgui.exe
@end example

@noindent
(or use @command{Rterm.exe}.)  However, note

@itemize @bullet
@item
@command{gdb} may only be able to find the source code if we run in the
location where the source was compiled (@file{@RWVER@/src/gnuwin32} for
the main system, @file{@RWVER@/src/library/mypkg/src} for a package),
unless told otherwise by the @command{directory} command.  It is most
convenient to set a list of code locations via @command{directory} commands
in the file @file{.gdbinit} in the directory from which @command{gdb} is
run.

@item
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} in
package @code{stats} might be

@example
     gdb ../../../../bin/x64/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
     Rconsole> example(line)
     ...
@end example

@noindent
Alternatively, in @command{Rgui} you can use the `Misc|Break to
debugger' menu item after your DLL is loaded.  The C function call
@code{breaktodebugger()} will do the same thing.

@item
Fortran symbols need an underline appended.

@item
Windows has little support for signals, so the Unix 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 MinGW version of
@command{gdb}.  It does often work with the @code{cygwin} version.

@end itemize


@node  How do I include C++ code?
@section  How do I include C++ code?

You need to do two things:

(a) Write a wrapper to export the symbols you want to call from R as
 @code{extern "C"}.

(b) Include the C++ libraries in the link to make the DLL.  Suppose
@file{X.cc} contains your C++ code, and @file{X_main.cc} is the wrapper,
as in the example in @emph{`Writing R Extensions'}.  Then build the DLL by
(@command{gcc})

@example
...\bin\x64\R CMD SHLIB X.cc X_main.cc
@end example

@noindent
or (@I{VC++}, which requires extension @code{.cpp})

@example
cl /MT /c X.cpp X_main.cpp
link /dll /out:X.dll /export:X_main X.obj X_main.obj
@end example

@noindent
and call the entry point(s) in @code{X_R}, such as @code{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.


@node  The output from my C code disappears.
@section  The output from my C code disappears.  Why?

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

Note that output from the console is delayed (@pxref{The output to the
console seems to be delayed}), so that you will not normally see any
output before returning to the R prompt.


@node  The output from my Fortran code disappears.
@section  The output from my Fortran code disappears.  Why?

Writing to Fortran output writes to a file, not the @command{Rgui} console.
Use one of the subroutines @code{dblepr}, @code{intpr} or @code{realpr},
@pxref{Printing from Fortran, , , R-exts, Writing R Extensions}.

Note that output from the console is delayed (@pxref{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 @code{xxxpr}
subroutines.


@node  The console freezes when my compiled code is running
@section The console freezes when my compiled code is running.

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


@set LASTEDIT 2024-04-05
@ifhtml
@html
<hr>
<address>
Last edited @value{LASTEDIT}: comments to
<code><a href="mailto:R-windows@@R-project.org">R-windows@@R-project.org</a></code>
</address>
@end html
@end ifhtml
@ifinfo
@sp 2
Last edited @value{LASTEDIT}: comments to @email{R-windows@@R-project.org}
@end ifinfo

@bye

@c Local Variables: ***
@c mode: TeXinfo ***
@c End: ***
