Introduction and notation
This vignette contains instructions on installing and configuring R, RStudio, and Rtools.
In this vignette, text between angled brackets
(<...>) is used to refer to text that should be
replaced with specific text to get working code. For example,
<pkgname> is used as a place holder to refer to a
package name and should be replaced with utils if you want
to obtain information about package utils, and with
methods if you want to obtain information about package
methods. Similarly, <funcname> is used
as a place holder to refer to a function name that should be filled in
with a specific function name to get working code.
R
To install R, visit a nearby
CRAN mirror (i.e.,
a website with the same content as the main CRAN page), download R via
Download R for Windows > base >
Download R-X.Y.Z for Windows and install it by opening the
downloaded .exe-file.
Note that R is not required to read R-scripts: R-scripts are plain-text files that can be read by applications such as Microsoft NotePad.
Configuring R
R can be configured to be a bit stricter, described in the help files
for general options (help("options")) and environment
variables (help("environment variables")):
- Warn in case of partial matching (
help("pmatch")) such aslist(mean = 3)$me:options(warnPartialMatchArgs = TRUE, warnPartialMatchAttr = TRUE, warnPartialMatchDollar = TRUE). The default isFALSEfor each of these. - Error instead of warn when calling
a:bwhen numericaorbis longer than one, such as3:c(5, 7)(introduced in R 4.3.0):Sys.setenv("_R_CHECK_LENGTH_COLON_" = "TRUE"). - Error instead of silently using only the first element in logical
operations (
help("Logic", package = "base")) such asc(TRUE, TRUE) && TRUE)(introduced in R 3.6.0, no longer used since R 4.3.0 because there calling&&or||with length larger than one always gives an error):Sys.setenv("_R_CHECK_LENGTH_1_LOGIC2_" = "TRUE"). - Error instead of warn if a condition
(
help("Control", package = "base")) has length larger than one, such asif(3 < c(5, 7)) {print("Not OK")}(introduced in R 3.y.z, no longer used since R 4.2.0 because there conditions with length larger than one always give an error):Sys.setenv("_R_CHECK_LENGTH_1_CONDITION_" = "TRUE"). - Print
warnings()immediately as they occur (options(warn = 1)) or makewarningsan error (help("stop")):options(warn = 2). The latter should only be used for debugging because it may trigger bugs and resource leaks (per its help-page). The default isoptions(warn = 0)to warn after the top-level function returns. - Enter the [environment browser][browser()] upon error (default:
options(error = NULL)):options(error = browser); pressQorEscapeto quit the browser mode; presscto continue code.
In addition, various packages contain ways to make R stricter:
- Package strict warns
about various unsafe practices, such as the behaviour of
sample()anddiag()if called with an argument of length one and type-unsafesapply(); additional ideas are in the GitHub issues. - Package conflicted
avoids silent conflict resolution (i.e., choosing the latest attached
package out of multiple packages to use a function from; see
help("conflict")), and providesconflicts_prefer(<pkgname>::<funcname>)to declare preferences once.
Finally, options for startup (described in
help("Startup")) and installing packages (see
help("install.packages") and
help(".libPaths")) can be used to configure R but can also
lead to code that behaves different on PCs where these options are not
set, such that they, for example, do not automatically load a package or
add a path to the search path.
Information about R
Several variables and functions provide information about R and the current R session:
-
.Machine(seehelp(".Machine")) andSys.info()provide information about the machine and platform R is running on.getRversion()provides the version of the running R. -
.Platform(seehelp(".Platform")) andR.Version()provide information about the platform R was built on. -
Sys.getlocale()provides details about the locale. -
sessionInfo()extracts parts of the information provided by the functions mentioned above about the operating system and R. It also lists attached and loaded packages. Its printing method can be used to print additional information about the used locale, time zone, and random number generation:print(sessionInfo(), locale = TRUE, RNG = TRUE). -
capabilities()andextSoftVersion()provide details about external software that can be used with R. - The help page on environment variables
(
help("environment variables")) lists some of the environment variables which affect an R session.
How operating systems identify themselves and their versions can be
arcane, and specifically Windows versions might report older versions
than the versions that are actually installed (see the section
osVersion in help("sessionInfo") and the
Note in help("win.version").
RStudio
RStudio is an integrated development environment for R that can be downloaded from Posit.
RStudio can also be used to read and modify plain-text files.
Configuring RStudio
After installing RStudio, start RStudio, go to Tools
> Global Options > General to
deselect the option
Restore .RData into workspace at startup and set the option
Save workspace to .RData on exit to Never to
make work portable.
The version of RStudio to use can be selected at Tools
> Global Options > General >
R version.
Keyboard shortcuts can be modified at Tools >
Modify Keyboard Shortcuts, e.g., to change the shortcut
Run current line or selection from Ctrl+Enter
to Ctrl+R so it can be used with one hand. Sometimes
RStudio does not use the modified keyboard shortcuts. Going to
Tools > Modify Keyboard Shortcuts usually
fixes that without the need to actually reset the shortcuts.
The appearance of code can be changed at Tools >
Global options > Appearance. The default
Editor theme is the light Textmate, another
nice light Editor theme is Xcode. Nice dark
Editor themes are Tomorrow Night Bright,
Idle Fingers, and Pastel On Dark, with
Editor fonts Consolas,
Cacadia Mono Light, or Lucida Console.
To check that characters in a typeface or font can be properly
distinguished from each other when choosing a font, for example using Adobe Fonts or Google Fonts, the following string
groups together characters that in some fonts are similar in appearance:
71lI|i/ oQO0D gq B8 S5 Z2 ijy4 ., :; "'' __ cldcIdc|dc1d rnm UVVWuvvw
The string consists of the following characters (using upper case letter that are easier to distinguish, with ‘lower’ and ‘upper’ indicating the case used in the string):
- SEVEN, ONE, lower EL, upper I, vertical BAR, lower I, SLASH
- lower O, upper CUE, upper O, ZERO, upper DEE
- lower GEE, lower CUE
- upper BEE, EIGHT
- upper ESS, FIVE
- upper ZED, TWO
- lower I, lower JAY, lower WYE, FOUR
- DOT, COMMA,
- COLON, SEMICOLON
- double QUOTES, single QUOTES, single QUOTES
- UNDERSCORE, UNDERSCORE
- lower CEE, lower EL, lower DEE, lower CEE, upper I, lower DEE, lower
CEE,
vertical BAR, lower DEE, lower CEE, ONE, lower DEE - lower AR, lower EN, lower EM
- upper U, upper VEE, upper VEE, upper double-U,
lower U, lower VEE, lower VEE, lower double-U
Rtools
Rtools
is not an R package but software used to build R from source and to
build R packages from source: packages from GitHub and older
versions of packages from CRAN or Bioconductor
(see the section ‘Installing packages’ in the vignette R
packages for instructions:
vignette("r_pkgs", package = "checkrpkgs")). Rtools is
not needed to install current versions of packages from
CRAN or
Bioconductor on Windows.
To install Rtools,
download the version appropriate for the installed version of R (see the
output of getRversion()) from CRAN via
Download R for Windows > Rtools >
RTools X.Y and set it up using the instructions given
there. See also the HowTo
by Tomas Kalibera. Alternatively,
pkgbuild::check_build_tools(debug = TRUE) can be used to
check and install Rtools.
Documentation and help
- Bug reporting, linking to bugzilla
- CRAN homepage
- R FAQs
- R help: from inside R through
help.start()or online via https://cran.r-project.org/search.html - R homepage
- R mailing lists with a web interface with information and archives and a mirror for searching
- R manuals, especially the R Installation and Administration manual, with derived versions better suited for searching.
- R news
- RStudio user guide by Posit
- search engines specific for R;
- StackOverflow posts with the r-tag
- The book What They Forgot to Teach You About R
For developers
- CRAN mirrors: see the section ‘Other repositories and mirrors’ in
the vignette R packages:
vignette("r_pkgs", package = "checkrpkgs") - R developer page
- R development guide from the R Contribution Working Group
- R news (devel)