Rev 8712 | Blame | Last modification | View Log | Download | RSS feed
R for Windows FAQFrequently Asked Questions on R for WindowsVersion for rw1010Brian 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 How can I keep workspaces for different projects in different directories?2.5 How do I print from R?2.6 Can I use `R BATCH'?2.7 Can I use rwXxxx with ESS and emacs?2.8 What are HOME and working directories?3 Packages3.1 Can I install packages (libraries) in this version?3.2 I don't have permission to write to the `rwXxxx/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.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!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 debug code that I have compiled and dyn.load-ed?7.3 How do I include C++ code?7.4 The output from my C code disappears. Why?7.5 The output from my Fortran code disappears. Why?1 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,(`rw1000' or later); the current version is often called something like`rw1010' (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/windows-NT/base' directory andcollect the files you need. You will need at least the filesrwXxxxb1.zip rwXxxxb2.ziprwXxxxh.zip (text help) or rwXxxxch.zip (Compiled HTML help)and you may want `rwXxxxwh.zip' (the Windows help files) or`rwXxxxw.zip' (the HTML format help files), `rwXxxxl.zip' (the LaTeXformat help files, used for offline printing), or `rwXxxxd?.zip' (thedraft manuals, in PDF).Optionally, you can download the installer, `rwinst.exe'.2.2 How do I install R for Windows?===================================First, you need Windows 95 or 98 or NT4 or 2000: Windows 3.11+win32swill not work. Your file system must allow long file names (as islikely except perhaps for some network-mounted systems).The simplest way is to run the installer (double-click on the icon for`rwinst.exe' and navigate its wizard-like pages). Alternatively, choosea location and unzip the zip files (with a tool that preserves longfile names and the directory structure: we recommend the INFO-ZIPproject's `unzip'). All the files will unpack into a directory called`rwXxxx', for some `Xxxx'.Choose a working directory for R. Make a shortcut to`rwXxxx\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 theTarget field. We use `--vsize=10M --nsize=400k'. You can also setenvironment variables at the end of the Target field, for example`R_LIBS=e:/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 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.2.5 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'.* 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.6 Can I use `R BATCH'?========================No, but you can set up a batch file using `rterm.exe'. A sample batchfile might contain (as one line)path_to_R\bin\rterm.exe --vsize=10M --nsize=500k --no-restore --no-save < %1 > %1.out2.7 Can I use rwXxxx with ESS and emacs?========================================Yes. The latest versions of ESS (e.g. 5.1.13) come with support for thisversion of R, and there is support for interrupting the R process fromESS (by `C-c C-c').For help with ESS, please send email to `ESS-help@stat.ethz.ch', notthe R mailing lists.2.8 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 `getenv("R_USER")'.3 Packages**********3.1 Can I install packages (libraries) in this version?=======================================================Yes, of course. The easy way is to see if a pre-compiled binary versionof the package is available: look on CRAN at`bin/windows/windows-NT/contrib'. If there is, download the zip fileand unpack it in the `rwXxxx\library' directory, using `unzip' orsimilar, or using the installer `rwinst.exe'. Perhaps even easier isto use the R function `install.packages()': check out its help page.If there is not a binary version or that is not up-to-date or you prefercompiling from source, get `rwXxxxsp.zip' from the distribution (seeQ1.1) and unpack it in `rwXxxx'. Then `cd src\gnuwin32' and read`README.packages'. You will need to collect and install several toolsto use this. Once you have done so, installation is easy: just run`make pkg-pkgname'. To check the package (run all the examples on itshelp pages) use `make pkgcheck-pkgname'.3.2 I don't have permission to write to the `rwXxxx/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 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 which youlaunch `Rgui' / `Rterm'. Under Windows NT/2000 you can use the controlpanel or the properties of `My Computer'. You can also set them on thecommand line, for example in the shortcut you could havepath_to_R\bin\rgui.exe --vsize=10M R_LIBS=e:/R/libraryand you can set variables in a file `.Renviron' in the working directoryor your home directory, for exampleR_LIBS=e:/R/libraryR_VSIZE=10MR_NSIZE=400kThe order of precedence is the command line (flags before variables)then `.Renviron' then the inherited environment.You can also build packages from anywhere to anywhere, but may besimpler to install a private copy of R to do the building.3.3 The packages I installed do not appear in the HTML help system.===================================================================HTML help only works for packages installed in `rwXxxx\library'.To update the HTML help files after you have installed a binary package,run at the R prompt.> link.html.help()(Using `install.packages()' does this for you. The source-codeinstallation also does this automatically, and if you have thatinstalled you can use (preferably)cd rwXxxx\src\gnuwin32\helpmake indicesinstead.)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 `rwXxxx\library'.* the package contains a `CONTENTS' file in top-level directory (afew of the binary distributions do not).* you updated the indices as described in the answer to Q3.3 afterinstalling the package.If those all hold true, this works for us.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 much simpler thanthe readline-based editing on Unix. For `rgui.exe', the menu item`Help | Console' will give details.* The commands history is saved between sessions only on `rgui.exe',and it is always saved.* Using `help.start()' does not automatically send help requests tothe browser: use `options(htmlhelp=T)' 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' or`metafile'. There are right-click menus giving shortcuts to menu items,and optionally toolbars with buttons giving shortcuts to frequentoperations.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'. From `rw1010' there is a Preferences editorinvoked from the `Edit' menu which can be used to edit the file`Rconsole'.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 Image' menu item.5.3 Can I load workspaces saved under Unix/GNU-Linux?=====================================================Yes. The converse (saving on Windows, loading on Unix) also works.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 doesFixedSys. 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, or thehorizontal scrollbar.7 Building from Source**********************7.1 How can I compile R from source?====================================Get the R sources. Suppose you want to compile R-1.1.0.tar zxvf R-1.1.0.tgzcd R-1.1.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 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 DEBUG=T pkg-mypkgThen you can debug bygdb /path/to/rwXxxx/bin/Rgui.exeHowever, note* gdb will only be able to find the source code if we run in thelocation where the source was compiled (`rwXxxx/src/gnuwin32' forthe main system, `rwXxxx/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 the linksat `http://sourceware.cygnus.com/cygwin') and provides a graphical userinterface to `gdb'. Another (Windows-native) GUI for `gdb' is`Insight', from`ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/cygwin/ports/'.7.3 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_R.cc' is the wrapper. Then buildthe DLL by (`gcc-2.95.x')g++ -c X.cc X_R.ccdlltool --export-all-symbols --output-def X.def X_R.odllwrap -o X.dll --def X.def X.o X_R.o -lstdc++or (VC++)cl /MT /c X.cpp X_R.cpplink /dll /out:XX.dll /export:X_main X.obj X_R.objand 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.7.4 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'.7.5 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.Last edited 2000 April 28 by Brian Ripley <ripley@stats.ox.ac.uk>