英文原版信息来自 www.r-project.org ,
由B. D. Ripley 和 D. J. Murdoch编写
由 EDS 提供中文翻译
R CMD BATCH
吗?
此FAQ是针对windows下的R: 描述的特性是针对这个版本. 主要的R FAQ 可以去这里找
http://CRAN.R-project.org/doc/FAQ/R-FAQ.html.
此信息只针对windows系统下近期发布的R版本, (`2.10.0' 或 更新). 主要针对32bit编译, 有一些提到了64bit编译 (需要在 `2.11.0' 版本或 更新).
在 CRAN 站点 (列表 http://cran.r-project.org/mirrors.html ), 进入 bin/windows/base 目录 查找你需要的文件. 当前发布的安装版 `R-2.11.1-win32.exe' 大小:32Mb. 它包含了所有组件,并且可以自选择安装。
在那个页面中也包含 `r-patched' 和 `r-devel' 的发布. 都是R的最近更新。 `r-patched' 当前版本包含bug的修复, 并且 `r-devel' 包含一些升级修改,这些修改将发布于下一个版本 `x.y.0' .
当前版本的R需要运行于windows2000或更高版本.【低版本对应】, 如果是64位R安装: 请看 怎样在64位windows下使用R?.
我们仅在微软发布的当前版本上测试,主要是 32bit winXP sp3 和 64bit windows7 以及 windows server 2008。
你的文件系统必须能够支持长文件名。典型安装需要45Mb的磁盘空间,完整安装大概需要65Mb,最小安装需要29M不。
如果你希望能够正常编译源码,我们建议你选择安装路径的时候不要包括空格。(使用空格也许不会有影响,但是没有经过严格测试。) Vista/Windows 7/Server 2008 下建议使用administrator权限的用户安,装2 不建议安装到系统盘 (例:
C:\R). 也不支持直接安装到网络路径 (例:
\\machine\...
) : 这种网络路径需要镜像为一个网络驱动盘.
运行安装 `R-2.11.1-win32.exe'. 如果你有administrator权限,R将被安装到 Program Files 并且设置所有的可选的注册表项; 否则你只能在你自己的空间安装R. 在当前的windows版本中,你可能需要确认一个 `未认证的发布者'提示,以继续安装.
安装完成后你需要选择设置一个R的工作路径. 你将看到桌面上和开始菜单中被创建一个快捷方式指向 R-2.11.1\bin\Rgui.exe . 右击一个快捷方式, 选择 Properties... 并且在 `Start in' 中修改工作路径.
你有可能需要在最后的标签中添加命令行参数 (任何双中线参数之后, 需要一个空格分割), 例如 --sdi --max-mem-size=1G
. 你可以在作后的标签中配置环境变量, 例如:R_LIBS=p:/myRlib
, 并且可以设置IDE语言, LANGUAGE=en
.
也可能是一个32bit的MSI安装文件,该文件只有系统管理员会有兴趣。对于如何建立一个 MSI文件,可以看看`R安装和管理手册'。
Relates to earlier installers, removed in R 2.11.0.
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.
tests
.
It is also possible to save the settings used to a file and later reload those settings using
A successful installation has exit code 0: unsuccessful ones may give 1, 2, 3, 4 or 5. See the help for Inno Setup (http://jrsoftware.org/ishelp.php) for details.
We have some facilities for building a customized installer, in particular to add packages to the installer. See the `R Installation and Administration' manual in the subsection `Building the installers'.
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 tcsh or 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.)
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.
Normally you can do this from the R group on the Start Menu or from the `Add/Remove Programs' or `Programs and Features' group in the Control Panel. If it does not appear there, run unins000.exe in the top-level installation directory. (There should be a separate uninstall item in the R group on the Start Menu for each installed version of R. On recent versions of Windows you may well be asked to confirm that you wish to run a program from an `unidentified publisher'.)
Uninstalling R only removes files from the initial installation, not (for example) packages you have installed or updated.
If all else fails, you can just delete the whole directory in which R was installed.
That's a matter of taste. For most people the best thing to do is to
uninstall R (see the previous Q), install the new version, copy any
installed packages to the library folder in the new installation, run
update.packages(checkBuilt=TRUE, ask=FALSE)
in the new R 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 wish.
For those with a personal library (folder R\win-library\x.y
of your home directory, R\win64-library\x.y on 64-bit
builds), you will need to update that too when the minor version of R
changes (e.g. from 2.10.1 to 2.11.0). A simple way to do so is to
copy (say) R\win-library\2.10 to R\win-library\2.11 before
running update.packages(checkBuilt=TRUE, ask=FALSE)
.
Indeed there is. It is set by the command-line flag --max-mem-size (see How do I install R for Windows?) and defaults to the smaller of the amount of physical RAM in the machine and 0.5GB less than the limit of user virtual memory for a process (most often 2GB on a 32-bit build). It can be set to any amount between 32Mb and 4095Mb (on a 32-bit build).
Use ?Memory
and ?memory.size
for information about memory
usage. The limit can be raised by calling memory.limit
within a
running R session.
The 32-bit executables Rgui.exe and Rterm.exe support up
to 3GB of user address space per process under suitably enabled versions
of 32-bit Windows (see
http://www.microsoft.com/whdc/system/platform/server/PAE/PAEmem.mspx,
http://msdn.microsoft.com/en-us/library/bb613473%28VS.85%29.aspx;
this is not enabled by default). On such systems, the default for
--max-mem-size
is the smaller of the amount of RAM and 2.5GB. On
all but the earliest 64-bit versions of Windows the user address space
for a 32-bit process is 4GB, and there the default for
--max-mem-size
is the smaller of the amount of RAM and 3.5GB.
For a 64-bit build, the default is the amount of RAM.
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 automatically helps separate projects.
Alternatively, start R by double-clicking on a saved .RData file in the directory for the project you want to use, or drag-and-drop a file with extension .RData onto an R shortcut. In either case, the working directory will be set to that containing the file.
It depends what you want to print.
dev.print
with suitable arguments (see its help page: most likely
dev.print(win.graph)
will work).
help(fn_name, help_type="postscript")
(or
"PDF"
).
R CMD BATCH
?Yes: use R CMD BATCH --help
or ?BATCH
for full details.
You can set also up a batch file using Rterm.exe. A sample batch file might contain (as one line)
path_to_R\bin\Rterm.exe --no-restore --no-save < %1 > %1.out 2>&1
The purpose of 2>&1
is to redirect warnings and errors to the
same file as normal output.
Yes. ESS has for a long time supported R under Windows: it does so by
running Rterm.exe
without a visible console.
For help with ESS, please send email to ESS-help@stat.ethz.ch, not the R mailing lists.
Several places in the documentation use these terms.
The working directory is the directory from which Rgui
or
Rterm was launched, unless a shortcut was used when it is given
by the `Start in' field of the shortcut's properties. You can find this
from R code by the call getwd()
.
The home directory is set as follows: If environment variable R_USER is set, its value is used. Otherwise if environment variable HOME is set, its value is used. After those two user-controllable settings, R tries to find system-defined home directories. It first tries to use the Windows "personal" directory (typically C:\Documents and Settings\username\My Documents on Windows XP and C:\Users\username\Documents on Vista). If that fails, if both environment variables HOMEDRIVE and HOMEPATH are set (and they normally are), the value is ${HOMEDRIVE}${HOMEPATH}. If all of these fail, the current working directory is used.
You can find this from R code by Sys.getenv("R_USER")
.
Environment variables can be set for Rgui.exe and Rterm.exe in three different ways.
"path_to_R\bin\Rgui.exe" HOME=p:/ R_LIBS=p:/myRlib
R_LIBS=p:/myRlib
If you have permission to do so, you can also create an environment file etc\Renviron.site and set environmental variables in that file in the same way. This is useful for variables which should be set for all users and all usages of this R installation. (Their values can be overridden in a .Renviron file or on the command line.)
See ?Startup
for more details of environment files.
The order of precedence for environmental variables is the order in which these options are listed, that is the command line then .Renviron then the inherited environment.
How did you specify it? Backslashes have to be doubled in R character strings, so for example one needs `"d:\\R-2.11.1\\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. `"xgobi.bat"' rather than just `"xgobi"'); sometimes this isn't shown in Windows, but it is necessary in R.
A simple way to avoid these problems is to use the function
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 `PROGRA~1'; you can get it as the
`MS-DOS name' from the Properties of the file on some versions of
Windows, and from dir /X in a `Command Prompt' window),
and using the function shortPathName
from R code.
Not when R itself is running.
When you run the R installer, there are options (under `Select Additional Tasks') to `Save version number in registry' and (for Administrator installs) `Associate R with .RData files'.
If you tick the first option, the following string entries are added to the Windows registry:
HKEY_LOCAL_MACHINE\Software\R-core\R\Current Version
contains the version number, currently 2.11.1.
HKEY_LOCAL_MACHINE\Software\R-core\R\[version]\InstallPath
(where [version]
is currently 2.11.1) contains the path to the R
home directory.
HKEY_CURRENT_USER
.
As from R 2.11.0 the same entries are also created under
Software\R-core\R32
or Software\R-core\R64
, for 32- and
64-bit R respectively.
If you tick the second option (shown with administrative privileges
only) (`Associate R with .RData files') then entries are created under
HKEY_CLASSES_ROOT\.RData
and HKEY_CLASSES_ROOT\RWorkspace
.
After installation you can add the Registry entries in by running
RSetReg.exe
in the bin
folder, and remove them by running
this with argument /U
. Note that this requires administrative
privileges unless run with argument /Personal
and neither sets up
nor removes the file associations.
Directly, no. See CRAN packages rscproxy
and rcom
as well
as RDCOMServer
, RDCOMClient
, RDCOMEvents
and
SWinTypeLibs
from http://www.omegahat.org/.
for example update.packages()
and the menu items on the Packages menu.
We have had several reports of this, although they do work for us on all of our machines. There are two known possible fixes.
(a) Use the alternative internet2.dll by starting R with the flag
--internet2 (see How do I install R for Windows?) or
calling setInternet2(TRUE)
. These cause R to use the Internet
Explorer internals, which may already to configured for use with
proxies. Note that this does not work with proxies that need
authentication.
(b) A proxy needs to be set up: see ?download.file
. Here are two
versions of an example (a real one, but from a machine that is only
available locally) of a command-line in a short cut:
"path_to_R\bin\Rgui.exe" http_proxy=http://user:pass@gannet:80/ "path_to_R\bin\Rgui.exe" http_proxy=http://gannet/ http_proxy_user=ask
The second version will prompt the user for the proxy username and password when HTTP downloads are first used.
Another possibility is that firewall settings are blocking the R executables from contacting the Internet, but this should result in informative error messages from the firewall program.
This has not been reported for a few years, but used to happen regularly. All the occurrences we have solved have been traced to faulty versions of `msvcrt.dll': we have installed a workaround that seems to avoid this. A few other people have discovered this was caused by desktop switcher and keyboard macro programs, for example `Macro Magic' and `JS Pager'.
This is a 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.
See also ?dyn.load
.
Some users have found that Rgui.exe
fails to start, exiting with
a “Floating-point invalid operation” or other low level error. This
error may also happen in the middle of a session. In some cases where
we have tracked this down, it was due to bugs in the video driver on the
system in question: it makes changes to the floating point control word
which are incompatible with R. (Good practice would restore the control
word to the state it was in when the driver code was called, and R
tries hard to correct this before running its own code.) For example,
one user reported that the virtual screen manager 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.
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 (as better written utilities do) but the usage as a percentage of the apparent total number of CPUs. We say `apparent' as it treats so-called `hyperthreaded' CPUs as two CPUs even though there is only one physical CPU: dual-core CPUs will also show as two CPUs (which they genuinely are) or more (since each core can be hyperhreaded).
Many benchmarks show hyperthreading reduces the overall workload, so you may want to experiment with disabling it.
It does. A few issues have been reported that related to the way accounts and file permissions work. (These are not specifically R issues, but changes in user experiences.)
Earlier versions of Windows had user and Administrator accounts, and user accounts could be give administrative privileges (by being added to the local Administrators group) and so write permission over system areas such as c:\Program Files. R would be installed either by a user in his 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 normally disables the Administrator account and expects software installation to 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) Windows XP, such accounts do not run programs with full administrator privileges, and this is where the issues arise. (For background information consult e.g. http://windowsvistablog.com/blogs/windowsvista/archive/2007/01/23/security-features-vs-convenience.aspx.) Vista has 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 will report that the R installer has an `unidentified 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. (The same issues apply to the .msi 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 Vista), 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 disallows creating .chm
and .dll
files in
the system area without credentials.) There are several ways around
this.
For an installation to be used by a single user, the simplest way is to make use of a `personal library': See I don't have permission to write to the R-2.11.1\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 R_LIBS_SITE in etc\Renviron.site. See What are HOME and working directories?. There is a standard location for a site library, the 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.
Another issue with Vista was that the standard POSIX ways that R uses
(e.g. in file.info
and file.access
) to look at file
permissions no longer work reliably. file.access
was re-written
to work with Windows NT-based security and the new version seems much
more reliable with Vista (but still not 100% correct).
On suitably recent hardware Vista can prevent the execution of code from data areas via `Data Execution Prevention' (from a tab in System Properties -> Advanced -> Performance), and sysadmins can turn this on for all programs. R runs correctly with DEP enabled.
R may make use of directional quotes that are not always rendered
correctly by Windows: these are used by default only by Rgui
in
suitable locales (not Chinese/Japanese/Korean).
Whether these are used in R output (from functions sQuote
and
dQuote
) is controlled by getOption("useFancyQuotes")
whose
default is FALSE
except for the Rgui
console. There are
two potential problems with rendering directional quotes. The first is
with running 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 chcp, with 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).
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 Rgui
console and internal pager is
Courier New
, which has directional quotes on all the systems we
tried. Lucida Console
has elegant glyphs for directional quotes,
but seems rather light on Windows XP (it looks better than Courier
New
on Vista): Consolas
is another font which we often select.
Non-TrueType fonts such as Courier
and FixedSys
lack
directional double quotes on all the systems we tried.
There is a related problem with using Sweave
output in
Rgui
, for LaTeX needs to be told about the encoding of
directional quotes by including in the LaTeX preamble e.g. (for a
Latin-1 locale)
\usepackage[cp1252]{inputenc}
or their use suppressed by options(useFancyQuotes=FALSE)
.
Where tilde does not appear on the main keyboard, it can normally be
accessed by pressing AltGr (the right Alt key) plus some other key.
This is ]
in Canadian (multilingual), German and Scandinavian
layouts, 1
in Eastern Europe, [
in Portuguese, 4
or
5
in Spanish, /
in Francophone Belgian, and so on. For
some keyboards the uses of AltGr are at
http://office.microsoft.com/en-us/word/HP052590631033.aspx: you
can explore those for your keyboard via the `On-Screen Keyboard' (under
Accessories, Accessibility on XP).
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, then releasing the Alt key.
The standard build of R for Windows is a 32-bit executable that will run on both 32-bit and 64-bit3 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).
As from R 2.11.0 there is a native 64-bit version of R: see the `R
Installation and Administration Manual'. A binary installer is
available from http://cran.r-project.org/bin/windows64/base/.
Most binary packages are available from CRAN or CRANextras (including
some from Omegahat and Rgraphviz
), but fewer hard-to-install
packages are available than for the standard 32-bit build. A subset of
Bioconductor packages are available.
For most users (especially beginners) we would recommend using the 32-bit build.
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 far less external software is available for 64-bit versions of the OS.
The toolchain (compilers, linkers, ...) used to build 64-bit R is less mature than that for 32-bit R, but testing so far (and all the CRAN packages provide an extensive test suite) suggests that they are mature enough for production use. The compilers are more recent versions of GCC with better optimization and are able to take advantage of extra features of all x86-64 chips (more registers, SSE2/3 instructions, ...) and so the code may run faster despite using larger pointers.
Obviously, only relevant if the machine is running a 64-bit version of Windows.
Yes, with a little care. For R 2.11.x they should be installed into different directories: the installer will suggest that the 64-bit build is installed into, say, R-2.11.0-x64 and Administrator installs will default to different paths (e.g. C:\Program Files (x86)\R for 32-bit, C:\Program Files\R for 64-bit). The Start Menu, desktop and quick launch icons will be named differently, and the versions can be uninstalled independently.
The default personal library directories are different. If you set the library path in a personal (rather than site) startup file it will need to choose one depending on the build, e.g.
.libPaths(if(.Machine$sizeof.pointer == 8) "~/Rlibs/x64" else "~/Rlibs/i386")
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, which will use the last installation for which this
option is selected. The situation with (optionally) recording the
version and install path is complex and may vary by the version of
Windows. But generally we find that with Administrator installs that
the 32-bit view of the Registry shows the last recorded 32-bit install,
and analogously for the 64-bit view, whereas for a user install the 32-
and 64-bit views are shared and so show the latest recorded
installation. To circumvent the latter, version information is also
recorded at Software\R-code\R32
or Software\R-code\R64
as
from R 2.11.0.
Only a limited range of languages is supported (but still wider than those for which R has translations), currently Brazilian Portuguese, Catalan, both Simplified and Traditional Chinese, Czech, Danish, Dutch, Finnish, French, German, Hebrew, Hungarian, Italian, Japanese, Korean, Norwegian, Polish, Portuguese, Russian, Slovak, Slovenian and Spanish (Spain).
The default behaviour of R is to try to run in the language you run Windows in.
Apparently some users want Windows in their native language, but not R.
To do so, set LANGUAGE=en
as discussed in Q2.2 and Q2.15, or in
the Rconsole file.
Windows versions of R support `East Asian' languages with a suitable copy of Windows – e.g. Western installations of Windows often do not have such support.
Both Rterm.exe and Rgui.exe support single- and
double-width characters. It will be necessary to select suitable fonts
in files Rconsole and Rdevga (see ?Rconsole
or the
comments in the files: the system versions are in the etc
folder); in the latter you can replace Arial
by Arial
Unicode MS
, and we tried FixedSys
and MS Mincho
in
Rconsole. (Note that Rdevga only applies to Windows
graphics devices and not, say, to 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 Lucida Console or Consolas.
You do need to ensure that R is running in a suitable locale: use
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'.) You can find
suitable locale names from
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_language_and_country_strings.asp:
beware that "Chinese"
is Traditional Chinese (code page 950,
Big5) and "chs"
is needed for Simplified Chinese (code page 936,
GB2312). Note that this can be rather tricky: on International versions
of Windows XP there are several places to select the language under the
`Regional and Language Options' part of the control panel, and the
appropriate language has to be set under both the `Regional
Options' and `Advanced' tabs.
When using Rterm the window in which it is run has to be set up to use a suitable font (e.g. Lucida Console, not the OEM raster fonts) and a suitable codepage (which for the Windows Cmd shell can be done by chcp).
Precisely, you selected English 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
locale: please read the appropriate manual (`R Installation and
Administration') for the details. You can ensure that R uses English
messages by appending LANGUAGE=en
to the shortcut you use to
start R, or setting it in the Rconsole file.
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 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 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 windowsFonts
has
examples of selecting Japanese fonts for the windows()
family of
devices.
In addition, the Hershey vector fonts (see ?Hershey
,
?Japanese
and demo(Japanese)
) can be used on any graphics
device to display Japanese characters.
To use non-Latin-1 characters in the postscript
graphics device,
see its help page (which also applies to pdf
).
You need to specify a font in Rconsole (see Q5.2) that supports the encoding in use, in Western European languages Latin-1. 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 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.
In most cases they actually are, but by Windows. Setting the locale
or the LANGUAGE
environment variable does not change the
Windows setting of its `UI language'. Under (international) Windows
XP there are three tabs on the Regional and Language Options
applet in the Control Panel. The first tab controls the locale, the
second the UI and the third the fonts used for `non-Unicode' programs
(but apparently also for Unicode ones in many cases): see Q3.3. Vista
talks about the 'UI language' and the 'system locale' for setting
the language used for `non-Unicode' programs.
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.
Yes, but you will need a lot of tools to do so, unless the author or the
maintainers of the bin/windows/contrib section on CRAN have been
kind enough to provide a pre-compiled version for Windows as a
.zip
file, or the package is a simple one involving no compiled
code (and pre-compiled versions are usually available for simple
packages).
You can install pre-compiled packages either from CRAN or from a local
.zip
file by using install.packages
: see its help page.
There are menu items on the Packages
menu to provide a
point-and-click interface to package installation. The packages for
each minor (2.x) version will be stored in a separate area, so for R
2.11.? the files are in bin/windows/contrib/2.11. You can try
those compiled for earlier versions (but not before 2.10.0), at your own
risk.
Note that the pre-compiled versions on CRAN are unsupported: see http://cran.r-project.org/bin/windows/contrib/ReadMe, which also gives the locations of a few other pre-compiled packages.
If there is not a pre-compiled version or that is not up-to-date or you
prefer compiling from source, read the `R Installation and
Administration' manual section on `Add-on Packages'. Source packages
which contain no C/C++/Fortran code which needs compilation can simply
be installed by install.packages(type = "source")
or R
CMD INSTALL pkgname. Otherwise you will need to collect and install
several tools: you can download them via the portal at
http://www.murdoch-sutherland.com/Rtools/. Once you have done
so, just run R CMD INSTALL pkgname. To check the package
(including running all the examples on its help pages and in its test
suite, if any) use R CMD check pkgname (which needs Perl
installed): see the `Writing R Extensions' manual.
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 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 http://win-builder.r-project.org.
You can install packages anywhere and use the environment variable R_LIBS (see How do I set environment variables?) to point to the library location(s).
Suppose your packages are installed in p:\myRlib. Then you can EITHER
set the environment variable R_LIBS to p:\myRlib before starting R
OR use a package by, e.g.
library(mypkg, lib.loc="p:/myRlib")
You can also have a personal library, which defaults to the directory
R\win-library\x.y of your home directory for versions
x.y.z of R. This location can be changed by setting the
environment variable R_LIBS_USER, and can be found from inside R
by running Sys.getenv("R_LIBS_USER")
. This will only be used if
it exists so you may need to create it: you can use
dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE)
to do so. If you use 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 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: See Does R run under Windows Vista?. In particular, the detection that a standard user has suitable permissions appears to be unreliable under Vista, so we recommend that you do create a personal directory yourself.
This question applied to the pre-2.10.0 HTML help system, which has been replaced.
This question applied to the pre-2.10.0 search system, which has been replaced.
Is the package compiled for this version of R? Many of the packages need to be compiled for a fairly recent version.
You can tell the version the package was compiled for by looking at the
`Built:' line in its DESCRIPTION file or at the
`Version' tab of its DLL in the libs directory.
(Right-click on the DLL in Windows Explorer and select `Version'
tab of the `Properties', or use the DLL.version
function
inside R.)
For a small number of binary packages you need to install additional
software and have its DLLs in your PATH
. Windows will normally
give an informative message about a certain DLL not being found (except
on Windows 2000). See
http://cran.r-project.org/bin/windows/contrib/2.11/ReadMe for a
listing of some of these packages (notably RGtk2
, rggobi
,
rJava
, rjags
and some of the packages connecting to
databases).
For package tcltk
to work (try demo(tkdensity)
or
demo(tkttest)
after library(tcltk)
) you need to have Tcl
installed. This is an optional part of the installation although it is
selected by default. If the message is
Tcl/Tk support files were not installed
the optional files were not installed, and you need to go back to the installer and install them.
Alternatively, if you have the environment variable MY_TCLTK set to a non-empty value, it is assumed that you want to use a different Tcl/Tk 8.5.x installation with the path to its bin directory given by value of MY_TCLTK, and that this is set up correctly (with TCL_LIBRARY set if needed). In that case you do not need the Tcl/Tk support files installed (but they can be). Note that you do need 8.5.x and not 8.4.x nor (a pre-release of) 8.6.0.
Several package authors have suggested using ActiveTcl
(http://www.activestate.com/Products/activetcl/) as a way to get
Tcl/Tk extensions (but the support files do contain the most commonly
used TkTable
and BWidget
extensions). This could be used
by setting (for a default install)
MY_TCLTK=c:/Tcl/bin
but current versions do not contain any extra extensions
(although they may be downloaded via the Teacup
facility).
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!
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 update.packages()
(or the menu equivalent) in a new session.
If you put library(foo)
in your .Rprofile you will need to
start R with --vanilla to be able to update package foo
.
If you set R_DEFAULT_PACKAGES to include 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, Google Desktop being a known example.
as shown in the Select repositories...
item on the
Packages
menu?
This reads from the tab-delimited file R_HOME\etc\repositories, which you can edit, or put a modified copy at .R\repositories in your HOME directory (see What are HOME and working directories?).
This was about Compiled HTML help, which is not supported since R 2.10.0.
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
R CMD INSTALL --html pkg1 pkg2 \ldots
To install R itself with static HTML pages change the following line in file MkRules
# set this to YES to build static HTML help BUILD_HTML = NO
and them all packages installed by that build of R will be installed with static HTML pages.
source()
) can be specified with
either "/" or "\\".
system()
is slightly different: see its help page and that
of shell()
.
You have read the file README.R-2.11.1? There are file menus on
the R console, pager and graphics windows. You can source and save from
those menus, and copy the graphics to png
, jpeg
,
bmp
, postscript
, PDF
or metafile
. There are
right-click menus giving shortcuts to menu items, and optionally
toolbars with buttons giving shortcuts to frequent operations.
If you resize the R console the options(width=)
is automatically
set to the console width (unless disabled in the configuration file).
The graphics has a history mechanism. As README.R-2.11.1 says:
`The History menu allows the recording of plots. When plots have been recorded they can be reviewed by <PgUp> and <PgDn>, saved and replaced. Recording can be turned on automatically (the Recording item on the list) or individual plots can be added (Add or the <INS> key). The whole plot history can be saved to or retrieved from an R variable in the global environment. The format of recorded plots may change between R versions. Recorded plots should not be used as a permanent storage format for R plots.There is only one graphics history shared by all the windows devices.'
The R console and graphics windows have configuration files stored in
the RHOME\etc directory called Rconsole and Rdevga;
you can keep personal copies in your HOME directory. They contain
comments which should suffice for you to edit them to your
preferences. For more details see ?Rconsole
.
There is a GUI preferences editor invoked from the Edit
menu which
can be used to edit the file Rconsole.
The graphics system asks Windows for the number of pixels per inch in
the X and Y directions, and uses that to size graphics (which in R are
in units of inches). Sometimes the answer is a complete invention, and
in any case Windows will not know exactly how the horizontal and
vertical size have been set on a CRT. You can specify correct values
either in the call to windows
or as options: see ?windows
.
(Typically these are of the order of 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!
You may want to do this from within a function, for example when calling `identify' or `readline'. Use the function `bringToTop()'. With its default argument it brings the active graphics window to the top and gives it focus. With argument `-1' it brings the console to the top and gives it focus.
This works for Rgui.exe in MDI and SDI modes, and can be used for graphics windows from Rterm.exe (although Windows may not always act on it).
Both Rgui and Rterm support TAB completion. Hitting TAB whilst entering a command line completes the current `word' as far as is unambiguously possible. Hitting 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 TAB again.
What is it `completing'? There are two modes: within an unterminated
(single- or double-) quoted expression it completes file paths.
Otherwise, it is completing R expressions: most obviously it will match
visible R object names and keywords, so apr folloed by TAB
will (in a vanilla session) complete to apropos
. After a
function name and parenthesis (e.g. apropos() it will complete
argument names (and =), and after $ or @ it will
complete list components or slot names respectively.
This feature can be turned off: Rgui has two menu items to do
so, and setting the environment variable R_COMPLETION to
FALSE
turns it off completely for both Rgui and
Rterm. Further, the behaviour can be fine-tuned: to see the
settings available use
?rc.settings
which also explains how the various types of completion work.
This feature is very similar to the completion available in the
readline
-based command line interface on Unix-alikes: the Mac OS
X GUI R.app
has a different completion scheme.
Have you changed the working directory?: see Q6.2.
Use the `File | Change Dir...' menu item to select a new working directory: this defaults to the last directory you loaded a file from. The workspace is saved in the working directory. You can also save a snapshot of the workspace from the `Save Workspace...' menu item.
From the command line you can change the working directory by the
function setwd
: see its help page.
Yes. All ports of R use the same format for workspaces, so they are interchangeable (for the same 2.x.? version of R, at least).
Note though that character data in a workspace will be in a particular encoding that is not recorded in the workspace, so workspaces containing non-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 (Mac OS X normally uses UTF-8, and Linux users are likely to use UTF-8 or perhaps Latin-1 (which used to be used for English)).
This is deliberate: the console output is buffered and re-written in chunks to be faster and less distracting. You can turn buffering off or on from the `Misc' menu or the right-click menu: <Ctrl-W> toggles the setting.
If you are sourcing R code or writing from a function, there is another
option. A call to the R function flush.console()
will write out
the buffer and so update the console.
They only seem to be truncated: that $ at the end indicates you can scroll the window to see the rest of the line. Use the horizontal scrollbar or the <CTRL + left/right arrow> keys to scroll horizontally. (The <left/right arrow> keys work in the pager too.)
To build R on 32-bit Windows you will need the tools from http://www.murdoch-sutherland.com/Rtools/ as well as some others. See the `R Installation and Administration' manual.
To build a 64-bit version on 64-bit Windows you will need a suitable
compiler, and the MinGW-w64 port of binutils
and gcc
is
finally mature enough to produce a working version of R, so support has
been added as from R 2.11.0: see the manual. You are welcome to try a
commercial compiler4, and pre-compiled versions using such compilers are available
from R redistributors.
Fast BLAS (Basic Linear Algebra Subprograms,
http://www.netlib.org/blas/faq.html) routines are used to speed
up numerical linear algebra. There is support in the R sources for the
`tuned' BLAS called ATLAS (http://math-atlas.sourceforge.net).
The savings can be appreciable: on a 2.6GHz P4 and a 1000 x 1000 matrix
svd
took 16.2 sec with the standard BLAS and 7.8 sec with ATLAS.
Because ATLAS is tuned to a particular chip we can't use it generally:
the optimal routines for a P4 or an Athlon XP are quite different and
neither will run at all on a PII.
BLAS support is supplied by the single DLL R_HOME\bin\Rblas.dll, and you can add a fast BLAS just by replacing that. Replacements for some of the older common chips are available on CRAN in directory bin/windows/contrib/ATLAS. See the R Installation and Administration' manual for how to build an ATLAS Rblas.dll tuned to your system using the R sources. Unfortunately the process has been less successful when tried for the common current chips such as Core 2.
We strongly encourage you to do this via building an R package: see the `Writing R Extensions' manual. In any event you should install the parts of the R system for building R packages (installed by default), and get and install the tools and compilers mentioned in the `R Installation and Administration' manual. Then you can use
...\bin\R CMD SHLIB foo.c bar.f
to make foo.dll. Use ...\bin\R CMD SHLIB --help for
further options, or see ?SHLIB
.
If you want to use Visual C++, Borland C++ or other compilers, see the appropriate section in README.packages.
You will need a suitable version of gdb: we normally use that
from the Cygwin distribution. Debugging under Windows is often a
fraught process, and sometimes does not work at all. If all you need is
a just-in-time debugger to catch crashes, consider
Dr. Mingw
from the mingw-utils
bundle on
http://www.mingw.org. That will be able to pinpoint the error,
most effectively if you build a version of R with debugging information
as described below.
First, build a version of the R system with debugging information by
make clean make DEBUG=T
and make a debug version of your package by either
make pkgclean-mypkg make DEBUG=T pkg-mypkg
or
Rcmd install -c mypkg set DEBUG=T Rcmd install mypkg
Then you can debug by
gdb /path/to/R-2.11.1/bin/Rgui.exe
However, note
tukeyline
in
package stats
might be
gdb ../../../../bin/Rgui.exe (gdb) break WinMain (gdb) run [ stops with R.dll loaded ] (gdb) break R_ReadConsole (gdb) continue [ stops with console running ] (gdb) continue Rconsole> library(stats) (gdb) break tukeyline (gdb) clear R_ReadConsole (gdb) continue Rconsole> example(line) ...
Alternatively, in Rgui you can use the `Misc|Break to debugger' menu item
after your DLL is loaded. The C function call breaktodebugger()
will do the same thing.
cygwin
version.
See http://www.stats.uwo.ca/faculty/murdoch/software/debuggingR/gdb.shtml for some further details.
You need to do two things:
(a) Write a wrapper to export the symbols you want to call from R as
extern "C"
.
(b) Include the C++ libraries in the link to make the DLL. Suppose X.cc contains your C++ code, and X_main.cc is the wrapper, as in the example in `Writing R Extensions'. Then build the DLL by (gcc)
...\bin\R CMD SHLIB X.cc X_main.cc
or (VC++, which requires extension .cpp
)
cl /MT /c X.cpp X_main.cpp link /dll /out:X.dll /export:X_main X.obj X_main.obj
or (Borland C++, which also requires extension .cpp
)
bcc32 -u- -WDE X.cpp X_main.cpp
and call the entry point(s) in X_R
, such as X_main
.
Construction of static variables will occur when the DLL is loaded, and
destruction when the DLL is unloaded, usually when R terminates.
Note that you will not see the messages from this example in the GUI console: see the next section.
This example used to be in package cxx_0.0-x.tar.gz in the src/contrib/Devel section on CRAN, and could be compiled as a package in the usual way on Windows.
The Rgui.exe console is a Windows application: writing to
stdout
or stderr
will not produce output in the
console. (This will work with Rterm.exe.) Use Rprintf
or
REprintf
instead. These are declared in header file
R_ext/PrtUtil.h.
Note that output from the console is delayed (see The output to the console seems to be delayed), so that you will not normally see any output before returning to the R prompt.
Writing to Fortran output writes to a file, not the Rgui console.
Use one of the subroutines dblepr
, intpr
or realpr
documented in the `Writing R Extensions' manual.
Note that output from the console is delayed (see The output to the console seems to be delayed), so that you will not normally see any
output before returning to the R prompt even when using the xxxpr
subroutines.
The console, pagers and graphics window all run in the same thread
as the R engine. To allow the console etc to respond to Windows events,
call R_ProcessEvents()
periodically from your compiled code.
If you want output to be updated on the console, call
R_FlushConsole()
and then R_ProcessEvents()
.
R-windows@r-project.org
[1] R 2.6.2 was the last version for Windows 95. 98, ME and NT4.
[2] Non-administrator accounts will automatically be offered a default installation directory in the user area.
[3] what Windows calls x64 for x86-64 CPUs, not the very rare ia64 Windows for Itanium CPUs.
[4] such as those from Intel and PGI: there is
no Fortran compiler in the Microsoft set, but f2c
could be
used.