Rev 15257 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
R for Windows FAQFrequently Asked Questions on R for WindowsVersion for rw1040Brian RipleyTable of Contents*****************1 Introduction2 Installation and Usage2.1 Where can I find the latest version?2.2 How do I install R for Windows?2.3 How do I run it?2.4 There seems to be a limit on the memory it uses!2.5 How can I keep workspaces for different projects in different directories?2.6 How do I print from R?2.7 Can I use `R BATCH'?2.8 Can I use rw1040 with ESS and emacs?2.9 What are HOME and working directories?2.10 R can't find my file, but I know it is there!2.11 Does R use the Registry?2.12 Entering certain characters crashes Rgui.3 Packages3.1 Can I install packages (libraries) in this version?3.2 I don't have permission to write to the `rw1040\library' directory.3.3 The packages I installed do not appear in the HTML help system.3.4 My functions are not found by the HTML help search system.3.5 Loading a package fails.3.6 Package TclTk does not work.3.7 Hyperlinks in Compiled HTML sometimes do not work.4 Windows Features4.1 What should I expect to behave differently from the Unix version of R?4.2 I hear about some nifty features: please tell me about them!4.3 Circles appear as ovals on screen4.4 How do I more focus to a graphics window or the console?5 Workspaces5.1 My workspace gets saved in a strange place: how do I stop this?5.2 How do I store my workspace in a different place?5.3 Can I load workspaces saved under Unix/GNU-Linux?6 The R Console and Fonts6.1 I would like to be able to use Japanese fonts6.2 I don't see characters with accents at the R console, for example in ?text.6.3 When using Rgui the output to the console seems to be delayed.6.4 Long lines in the console or pager are truncated.7 Building from Source7.1 How can I compile R from source?7.2 How do I include compiled C code?7.3 How do I debug code that I have compiled and dyn.load-ed?7.4 How do I include C++ code?7.5 The output from my C code disappears. Why?7.6 The output from my Fortran code disappears. Why?7.7 The console freezes when my compiled code is running.7.8 The Perl scripts don't seem to work under Windows 9x/ME1 Introduction**************This FAQ is for the Windows port of R: it describes features specific tothat version. The main R FAQ can be found at`http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html'.The information here applies only to recent versions of R for Windows,(`rw1020' or later); the current version is often called something like`rw1040' (although not officially).2 Installation and Usage************************2.1 Where can I find the latest version?========================================Go to any CRAN site (see `http://cran.r-project.org/mirrors.html' for alist), navigate to the `bin/windows/base' directory and collect thefiles you need. There are three possibilities.1) `SetupR.exe', is about 15Mb and gives a complete installation.2) Directory `miniR' contains `miniR.exe' and six files `miniR-?.bin'.You can put `miniR.exe' and `miniR-1.bin' on one floppy and theremaining `miniR-?.bin' on a floppy each.3) Via zip files in directory `zip'. You will need at least the filesrw1040b1.zip rw1040b2.ziprw1040h.zip (text help) or rw1040ch.zip (Compiled HTML help)and you may want `rw1040w.zip' (the HTML format help files),`rw1040l.zip' (the LaTeX format help files, used for offline printing),or `rw1040d?.zip' (the draft manuals, in PDF).2.2 How do I install R for Windows?===================================First, you need Windows 95/98/ME/NT4/2000: Windows 3.11+win32s will notwork. Your file system must allow long file names (as is likely exceptperhaps for some network-mounted systems).The simplest way is to use `SetupR.exe' or `miniR.exe'. Justdouble-click on the icon and follow the instructions. If you installedR this way you can uninstall it from the Control Panel or Start Menu(unless you supressed making a group for R).For a manual installation, choose a location and unzip the zip files(with a tool that preserves long file names and the directory structure:we recommend the INFO-ZIP project's `unzip'). All the files willunpack into a directory `rw1040'.Choose a working directory for R. Unless you used `SetupR.exe' or`miniR.exe' (which did this for you by default), make a shortcut to`rw1040\bin\Rgui.exe' on your desktop or somewhere on the Start menufile tree. Right-click the shortcut, select Properties... and changethe `Start in' field to your working directory.You may also want to add command-line arguments at the end of the Targetfield, for example `--sdi --max-mem-size=40M'. You can also setenvironment variables at the end of the Target field, for example`R_LIBS=p:/R/library'.2.3 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 theexisting one and change the `Start in' field of the Properties.2.4 There seems to be a limit on the memory it uses!====================================================Indeed there is. It is set by the command-line flag `--max-mem-size'and defaults to the smaller of the amount of physical RAM in themachine and 256Mb. It can be set to any amount over 10M. Be awarethough that Windows has (in most versions) a maximum amount of uservirtual memory of 2Gb, and parts of this can be reserved by processesbut not used. R itself reserves 256Mb on startup. Because of the waythe memory manager works, it is possible that there will be free memorybut R will not be able to reserve it.Use `?Memory' and `?memory.size' for information about memory usage.R can be compiled to use a different memory manager which may be betterat using large amounts of memory, but is substantially slower (making Rseveral times slower on some tasks).2.5 How can I keep workspaces for different projects in different directories?==============================================================================Create a separate shortcut for each project: see Q2.3. All the paths tofiles 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 inthe directory for the project you want to use, or drag-and-drop a filewith extension `.RData' onto an R shortcut. In either case, theworking directory will be set to that containing the file.2.6 How do I print from R?==========================It depends what you want to print.* You can print the graphics window from its menu or by using`dev.print()'.* You can print from the R console or pager by `File | Print'.(This will print the selection if there is one, otherwise thewhole console or pager contents.)* You can print help files from the pager or HTML browser.* If you have configured `RHOME\bin\helpPRINT.bat' and have LaTeXinstalled you can print help files by `help(fn_name,offline=TRUE)'.2.7 Can I use `R BATCH'?========================Yes, if you have Perl and the files for making source packages (from`SetupR.exe' or `rw1040sp.zip') installed. The Windows analogue is`Rcmd BATCH': use `Rcmd BATCH --help' for full details.Otherwise you can set up a batch file using `Rterm.exe'. A samplebatch file might contain (as one line)path_to_R\bin\Rterm.exe --no-restore --no-save < %1 > %1.out2.8 Can I use rw1040 with ESS and emacs?========================================Yes. The latest versions of ESS (e.g. 5.1.18) come with support forthis version of R, and there is support for interrupting the R processfrom ESS (by `C-c C-c').For help with ESS, please send email to <ESS-help@stat.ethz.ch>, notthe R mailing lists.2.9 What are HOME and working directories?==========================================Several places in the documentation use these terms.The working directory is the directory from which `Rgui' or `Rterm' waslaunched, 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 bythe call `getwd()'.The home directory is set as follows:If environment variable `R_USER' is set, its value is used.Otherwise if environment variable `HOME' is set, its value is used.Otherwise if environment variables `HOMEDRIVE' and `HOMEPATH' are set,the value is `${HOMEDRIVE}${HOMEPATH}'.If all of these fail, the current working directory is used.You can find this from R code by `Sys.getenv("R_USER")'.2.10 R can't find my file, but I know it is there!==================================================How did you specify it? Backslashes have to be doubled in R characterstrings, so for example one needs`"d:\\rw1040\\library\\xgobi\\scripts\\xgobi.bat"'. Make life easierfor yourself by using forward slashes as path separators: they do workunder Windows.Another possible source of grief is spaces in folder names. We havetried to make R work on paths with spaces in, but lots of people writingpackages for Unix do not bother. So it is worth trying the alternativeshort name (something like `PROGRA~1'; you can get it as the `MS-DOSname' from the Properties of the file on most versions of Windows).2.11 Does R use the Registry?=============================Not itself.The installers set some entries to allow uninstallation. In additionthey set a Registry key `LOCAL_MACHINE\Software\R-core\R' giving theversion and install path. Again, this is not used by R itself, but itwill be used by the DCOM interface(`http://cran.r-project.org/other-software.html'). Finally, a fileassociation for extension `.RData' is set in the Registry.You can add the Registry entries by running `RSetReg.exe' in the `bin'folder, and remove them by running this with argument `/U'. Note thatthe settings are all per machine and not per user, and that thisneither sets up nor removes the file associations.2.12 Entering certain characters crashes Rgui.==============================================This seems to happen occasionally, and all the occurrences we havesolved have been traced to faulty versions of `msvcrt.dll'. Tryextracting the one to be found in the self-extracting archive`ftp://ftp.microsoft.com/softlib/mslfiles/msvcrt.exe' and put it in the`rw1040\bin' directory. Removing `msvcrt.dll' from that directoryreverts to the standard behaviour.This fix has solved other problems too, for example incorrect results inthe date-time functions.3 Packages**********3.1 Can I install packages (libraries) in this version?=======================================================Yes, but you will need a lot of tools to do so, unless the author or themaintainers of the `bin/windows/contrib' section on CRAN has been kindenough to provide a pre-compiled version for Windows as a `.zip' file.You can install pre-compiled packages either from CRAN or from a local`.zip' file by using `install.packages': see its help page. There aremenu items on the `Packages' menu to provide a point-and-clickinterface to package installation.Note that the pre-compiled versions on CRAN are unsupported: see`http://cran.r-project.org/bin/windows/contrib/ReadMe'.If there is not a pre-compiled version or that is not up-to-date or youprefer compiling from source, get `rw1040sp.zip' from the distribution(see Q1.1; you may already have installed this from `SetupR.exe') andunpack it in the parent of `rw1040'. Then read the file`readme.packages'. You will need to collect and install several toolsto use this. Once you have done so, just run `Rcmd INSTALL pkgname'.To check the package (including running all the examples on its helppages and in its test suite, if any) use `Rcmd check pkgname': see the_`Writing R Extensions'_ manual.3.2 I don't have permission to write to the `rw1040\library' directory.=======================================================================You can install packages anywhere and use the environment variable`R_LIBS' to point to the library location(s). You can also set the Rvariable `.lib.loc' in your `.Rprofile' or when running R.Suppose your packages are installed in `p:\mylibs'. Then you can EITHERset the environment variable R_LIBS to p:\mylibsOR put in the `.Rprofile' in the working directory or your homedirectory.lib.loc <- c("p:/mylibs", .Library)OR use a package by, e.g.library(MASS, lib.loc="p:/mylibs")How you set an environment variable is system specific: in Windows 9xyou can set them in `autoexec.bat' or in an MS-DOS window from whichyou launch `Rgui' / `Rterm'. Under Windows NT/2000 you can use thecontrol panel or the properties of `My Computer'. Under Windows Me youneed to use the System Configuration Utility (under Programs,Accessories, System Tools on the Start menu). You can also set them onthe command line, for example in the shortcut you could havepath_to_R\bin\Rgui.exe R_LIBS=p:/mylibsand you can set variables in a file `.Renviron' in the working directoryor your home directory, for exampleR_LIBS=p:/mylibsThe order of precedence for environmental variables is the command linethen `.Renviron' then the inherited environment.3.3 The packages I installed do not appear in the HTML help system.===================================================================The HTML search only works for packages installed in `rw1040\library'.To update the HTML indices after you have installed a pre-compiledpackage, run at the R prompt.> link.html.help()This is done automatically when installing from the Packages menu or by`install.packages()'.3.4 My functions are not found by the HTML help search system.==============================================================The following conditions need to hold for functions in a package youinstalled.* the package is installed in `rw1040\library'.* the package contains a `CONTENTS' file in its top-level directory.* you updated the indices as described in the answer to Q3.3 afterinstalling the package.If those all hold true, this works for us.3.5 Loading a package fails.============================Is the package compiled for this version of R? Many of the packagesneed to be compiled for a fairly recent version, and in particular asubstantial minority need to be re-compiled for `rw1020' and later.You can tell the version the package was compiled for by looking at the`Built:' line in its `DESCRIPTION' file or at the `Version' tab of itsDLL (if it has one) in the `libs' directory. (Right-click on the DLLin Windows Explorer, and select `Properties' or use the `DLL.version'function inside R.) If there is no `Built:' line or version tab, thepackage was compiled too long ago.3.6 Package TclTk does not work.================================For package `tcltk' to work (try `demo(tkdensity)' or `demo(tkttest)'after `library(tcltk)') you need to have Tcl installed. Downloadeither ActiveTcl 8.3.3 from`http://aspn.activestate.com/ASPN/Downloads/ActiveTcl/' or `tcl832.exe'from `dev.scriptics.com' and install it. (That will put the `bin'directory containing the Tcl and Tk DLLs in your path). You then needto set the environment variable `TCL_LIBRARY', to something like`c:/Program Files/Tcl/lib/tcl8.3'. (The startup code for the packagewill warn you if this is unset, and Q3.2 explains how to set them. NB:do not quote the path, even if as here it contains spaces. If youforget, you can set the variable inside R by something likeSys.putenv("TCL_LIBRARY"="c:/Program Files/Tcl/lib/tcl8.3").)3.7 Hyperlinks in Compiled HTML sometimes do not work.======================================================Unfortunately, hyperlinks in compiled HTML files used from R areinterpreted relative to the current working directory of the R process,not relative to the `pkg.chm' file. This was not discovered until`rw1021': files made before that version work incorrectly. Remake thepackage to cure this.4 Windows Features******************4.1 What should I expect to behave differently from the Unix version of R?==========================================================================* R commands can be interrupted by <Esc> in `Rgui.exe' and<Ctrl-break> or <Ctrl-C> in `Rterm.exe': <Ctrl-C> is used forcopying in the GUI version.* Command-line editing is always available, but is simpler than thereadline-based editing on Unix. For `Rgui.exe', the menu item`Help | Console' will give details. For `Rterm.exe' see file`README.rterm'.* Using `help.start()' does not automatically send help requests tothe browser: use `options(htmlhelp=TRUE)' to turn this on.* The HTML help system can only access packages installed in thestandard place.* Paths to files (e.g. in `source()') can be specified with either"/" or "\\".* `system()' is slightly different: see its help page and that of`shell()'.4.2 I hear about some nifty features: please tell me about them!================================================================You have read the `README'? There are file menus on the R console,pager and graphics windows. You can source and save from those menus,and copy the graphics to `png', `jpeg', `bmp', `postscript', `PDF' or`metafile'. There are right-click menus giving shortcuts to menuitems, and optionally toolbars with buttons giving shortcuts tofrequent operations.If you resize the R console the `options(width=)' is automatically setto the console width (unless disabled in the configuration file).The graphics has a history mechanism. As the README says:`The History menu allows the recording of plots. When plots havebeen recorded they can be reviewed by <PgUp> and <PgDn>, saved andreplaced. Recording can be turned on automatically (the Recordingitem on the list) or individual plots can be added (Add or the<INS> key). The whole plot history can be saved to or retrievedfrom an R variable in the global environment.There is only one graphics history shared by all the windowsdevices.'The R console and graphics windows have configuration files stored inthe `RHOME\etc' directory called `Rconsole' and `Rdevga'; you can keeppersonal copies in your `HOME' directory. They contain comments whichshould suffice for you to edit them to your preferences. For moredetails see `?Rconsole'. There is a Preferences editor invoked fromthe `Edit' menu which can be used to edit the file `Rconsole'.4.3 Circles appear as ovals on screen=====================================The graphics system asks Windows for the number of pixels per inch inthe X and Y directions, and uses that to size graphics (which in R arein units of inches). Sometimes the answer is a complete invention, andin any case Windows will not know exactly how the horizontal andvertical size have been set on a CRT. You can specify correct valueseither in the call to `windows' or as options: see `?windows'.(Typically these are of the order of 80.)On one of our systems, the screen height is reported as 240mm, and thewidth as 300mm in 1280 x 1024 mode and 320mm in 1280 x 960 and 1600 x1200 modes. In fact it is a 21" monitor and 400mm x 300mm!4.4 How do I more focus to a graphics window or the console?============================================================You may want to do this from within a function, for example when calling`idenitfy' or `readline'. Use the function `bringToTop()'. With itsdefault argument it brings the active graphics window to the top andgives it focus. With argument `-1' it brings the console to the topand gives it focus.This works for `Rgui.exe' in MDI and SDI modes, and can be used forgraphics windows from `Rterm.exe'.5 Workspaces************5.1 My workspace gets saved in a strange place: how do I stop this?===================================================================Have you changed the working directory?: see Q5.2.5.2 How do I store my workspace in a different place?=====================================================Use the `File | Change Dir' menu item to select a new workingdirectory: this defaults to the last directory you loaded a file from.The workspace is saved in the working directory. You can also save asnapshot of the workspace from the `Save Workspace' menu item.From the command line you can change the working directory by thefunction `setwd': see its help page.5.3 Can I load workspaces saved under Unix/GNU-Linux?=====================================================Yes. The converse (saving on Windows, loading on Unix) also works onalmost all Unix systems, and workspaces can be interchanged with theMacintosh port too.6 The R Console and Fonts*************************6.1 I would like to be able to use Japanese fonts=================================================for example, in the console and to annotate graphs.We believe this is possible by setting suitable fonts in the Rconsoleand Rdevga configuration files (see Q4.2). You can specify additionalfonts in Rdevga, and use them bypar(font=, font.lab=, font.main=, font.sub=)Nineteen fonts are specified (as 1 to 19) by default: you can add tothese (up to 13 more) or replace them.6.2 I don't see characters with accents at the R console, for example in ?text.===============================================================================You need to specify a font in Rconsole (see Q4.2) that supports Latin1encoding. The default, `Courier New', does on our systems, as does`FixedSys'. This may be a problem in other locales, especially fornon-Western European languages.6.3 When using Rgui the output to the console seems to be delayed.==================================================================This is deliberate: the console output is buffered and re-written inchunks to be less distracting. You can turn buffering off or on fromthe 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 anotheroption. A call to the R function `flush.console()' will write out thebuffer and so update the console.6.4 Long lines in the console or pager are truncated.=====================================================They only *seem* to be truncated: that $ at the end indicates you canscroll the window to see the rest of the message. Use the horizontalscrollbar or the <CTRL+arrow> keys to scroll horizontally.7 Building from Source**********************7.1 How can I compile R from source?====================================Get the R sources. Suppose you want to compile R-1.4.0. Start in adirectory whose path does not contain spaces, and runtar zxvf R-1.4.0.tgzcd R-1.4.0cd src\gnuwin32Now read the `INSTALL' file and set up all the tools needed. Then youcan just use `make', sit back and wait. (A complete build takes about15 minutes on a 300MHz PII with a fast local disc.)You may need to compile under a case-honouring file system: we foundthat a `samba'-mounted file system (which maps all file names to lowercase) did not work.7.2 How do I include compiled C code?=====================================We strongly encourage you to do this _via_ building an R package: seethe _`Writing R Extensions'_ manual. In any event you should installthe parts of the R system for building R packages (in `SetupR.exe' or`rw1040sp.zip'), and get and install the tools (including Perl) andcompilers mentioned in the file `readme.packages' contained therein.Then you can use...\bin\Rcmd SHLIB foo.c bar.cto make `foo.dll'. Use `...\bin\Rcmd SHLIB --help' for furtheroptions, or see `?SHLIB'.If you want to use Visual C++, Borland C++ or other compilers, see theappropriate section in `readme.packages'.7.3 How do I debug code that I have compiled and dyn.load-ed?=============================================================First, build a version of the R system with debugging information bymake cleanmake DEBUG=Tand make a debug version of your package bymake pkgclean-mypkgmake DEBUG=T pkg-mypkgThen you can debug bygdb /path/to/rw1040/bin/Rgui.exeHowever, note* gdb will only be able to find the source code if we run in thelocation where the source was compiled (`rw1040/src/gnuwin32' forthe main system, `rw1040/src/library/mypkg/src' for a package),unless told otherwise by the `directory' command. It is mostconvenient to set a list of code locations via `directory'commands in the file `.gdbinit' in the directory from which `gdb'is run.* It is only possible to set breakpoints in a DLL after the DLL hasbeen loaded. So a way to examine the function `tukeyline' inpackage `eda' might begdb ../../../../bin/Rgui.exe(gdb) break WinMain(gdb) run[ stops with R.dll loaded ](gdb) break R_ReadConsole(gdb) continue[ stops with console running ](gdb) continueRconsole> library(eda)(gdb) break tukeyline(gdb) clear R_ReadConsole(gdb) continueFortran symbols need an underline appended.* Windows has little support for signals, so the usual idea ofrunning a program under a debugger and sending it a signal tointerrupt it and drop control back to the debugger does not workwith `mingw32' version of `gdb'. It does often work with the`cygwin' version.* We have seen examples in debugging problems with Windows eventsthat the `cygwin gdb' was able to catch but which terminated the`mingw32 gdb'.If you have an X server available on the PC, there is a version of`DDD' available that runs under the cygwin emulation layer (follow thelinks at `http://www.cygwin.com') and provides a graphical userinterface to `gdb'. Another (Windows-native) GUI for `gdb' is`Insight', part of the latest `cygwin' version of `gdb'.7.4 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`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 inthe example in _`Writing R Extensions'_. Then build the DLL by (`gcc')...\bin\Rcmd SHLIB X.cc X_main.ccor (VC++, which requires extension `.cpp')cl /MT /c X.cpp X_main.cpplink /dll /out:X.dll /export:X_main X.obj X_main.objor (Borland C++, which also requires extension `.cpp')bcc32 -u- -WDE X.cpp X_main.cppand call the entry point(s) in `X_R', such as `X_main'. Constructionof static variables will occur when the DLL is loaded, and destructionwhen the DLL is unloaded, usually when R terminates.Note that you will not see the messages from this example in the GUIconsole: see the next section.This example is in package `cxx_0.0-x.tar.gz' in the`src/contrib/Devel' section on CRAN, and that can be compiled as apackage in the usual way on Windows.7.5 The output from my C code disappears. Why?===============================================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 declaredin header file `R_ext/PrtUtil.h'.Note that output from the console is delayed (*note The output to theconsole seems to be delayed::), so that you will not normally see anyoutput before returning to the R prompt.7.6 The output from my Fortran code disappears. Why?=====================================================Writing to Fortran output writes to a file, not the `Rgui' console.Use one of the subroutines `dblepr', `intpr' or `realpr' documented inthe _`Writing R Extensions'_ manual.7.7 The console freezes when my compiled code is running.=========================================================The console, pagers and graphics window all run in the same thread asthe R engine. To allow the console etc to respond to Windows events,call `R_ProcessEvents()' periodically from your compiled code. If youwant output to be updated on the console, call `R_FlushConsole()' andthen `R_ProcessEvents()'.7.8 The Perl scripts don't seem to work under Windows 9x/ME===========================================================This has been seen under some versions of Perl and Windows version(95/98/ME) which use a 16-bit shell. Hopefully rw1030 and later aremore robust in this respect: it _may_ help to upgrade your Perl version(5.6.1, build 626 was current at the time of writing).Last edited 2001 June 21 by Professor B. D. Ripley<ripley@stats.ox.ac.uk>