Consider allowing JavaScript. Otherwise, the table of contents in the left column for navigation will not be available and code-folding not supported. Sorry for the inconvenience.

This article was originally generated with  4.0.5; updated with version 4.2.2 on Windows 7 build 7601, Service Pack 1, Universal C Run­time 10.0.10240.16390 and package rversions.1

• Click to show / hide R code.
• Click on the icon in the top left corner to copy R code to the clipboard.

# Introduction

There are excellent resources available on the net, esp. the R FAQ.2 However, for beginners or occasional users it might be too technical.

I’m assuming that you are running a 64 bit version of Windows (version 7 or later). If in doubt, right-click on Computer → Properties and under System / System type you will see whether it’s 32 or 64 bit. Although R comes in both flavours, I don’t recommend to run it on a 32 bit Operating System because you will be limited to 4 GB of memory – irrespective of how much RAM is installed on your machine. Furthermore, a 32 bit OS is no more supported by R 4.2.0 and later.

There are four possible scenarios:

1. In the ideal case you have local administrative privileges. Then you could install the 64 bit R to
C:\Program Files. For details see below.
2. If not, you can install R to the default user location, which is
C:\Users\UserName\AppData\Roaming. For details see below.
3. If your organization’s policy does not even allow that, you have to convince your boss that it’s just necessary to do your job.3
I suppose it is tempting, if the only tool you have is a hammer,
to treat everything as if it were a nail.
1. If you are not successful in #3:
• Explain that even most simple tasks (which may take you a minute) has to be outsourced. CDAs, time consuming paperwork to and fro, consultants’ ridiculous fees, etc.
• If not, consider to find another employer (not wearing a tin foil hat).

top of section ↩︎

Navigate to CRAN’s download site for Windows and click on the first link Download R x.y.z for Windows. The number x denotes a major, y a minor, and z a patch release.
If you didn’t change the location for downloaded files in your browser, the installer R-x.y.z-win.exe will be saved to C:\Users\UserName\Downloads.

Scenarios:

1. Right-click R-x.y.z-win.exe and select Run as Administrator. After providing your password, you will be asked by the installer which language should be used during the installation. This has nothing to do which language you will use later (see customization below).5
1. Click R-x.y.z-win.exe and you will be asked by the installer which language should be used during the installation. An information window appears.
By default R stores data in its own compressed binary format with the extension Rdata. Whilst you can still store/load data in this format, doubleclicking on such a file will not work.
Change UserName to yours. You can as well select any other (existing) folder. Important: You must have write permissions to this folder.

Installation common to both scenarios:

In the next window select 64-bit User Installation (only for releases up to 4.1.3). It saves more than 50 MB of disk space, since the 32-bit Files are not needed on a 64 bit Windows.

In the next window change from the default ⦿ No to ⦿ Yes.

In the next window change from the default ⦿ MDI to ⦿ SDI.

In the next window keep the default ⦿ HTML help (which will open manual pages in your default browser). Only if you are visually impaired, change to ⦿ Plain text (for screen readers or a braille display).

Keep the Start menu Folder in the next window.

In the next window I suggest to create a desktop shortcut. Only if you want to keep different versions in parallel, don’t save the version in the registry.

Hopefully the next window will look like this one:

# Customization

Navigate to your installation folder (in my example \R\R-4.0.5 and doubleclick to open it. Doubleclick the folder etc. Open the file Rconsole in a plain text editor. Edit the options as you like.
Here are parts of mine:
font = TT Lucida Console (I don’t like Courier)
xconsole = 40 (moves the R-console 40px to the right)
yconsole = 30 (moves the R-console 40px down)
language = en (I’m on a German locale but prefer English in R)
background cornsilk
normaltext navy
usertext red

Once you are done, save the file. Click on the desktop shortcut to open the R console. With my customization it looks like this:

In the menu bar click on Edit → GUI preferences… to check the results and adjust more if needed (e.g., on a high-resolution Retina display maybe you want a larger font size).

Mine again:

You can change any setting during an interactive session. That’s sometimes needed when you share your screen in a video conference.

For more customization edit the file Rprofile.site. Mine:

# To be consistant with the format on CRAN when creating package manuals
options(papersize="letter")
# Set the default help type
options(help_type="html")
# Change the default prompt from "> ", welcome,
# and don't ask stupid questions
options(prompt = "R> ", continue="+  ")
cat("Welcome at", date(), "\n")
utils::assignInNamespace(
"q",
function(save = "no", status = 0, runLast = TRUE) {
.Internal(quit(save, status, runLast))
}, "base"
)
# Change the system’s timezone to mine
Sys.setenv(TZ="Europe/Vienna")

# Packages, Libraries

There is some confusion about terminology.

• A package is a collection of R scripts for a specific purpose.
It always contains manual pages (help for a specific function opening in the browser), a complete manual in PDF-format on CRAN, and may contain data, test-scripts, custom documentation, and/or vignettes giving background information and more detailed examples.
Packages are hosted on CRAN (with November 2022 almost 19,000), Bioconductor, GitHub, SOURCEFORGE,…
Installation not from CRAN requires tools, C/C++ and Fortran compilers to built a package from the source code (provided in gzip-format) and is out of scope of this article.

Before you can use it, you have to attach it by executing the command library(foo), where foo is the name of the library.

Finding a suitable package is a cumbersome task. Google is your friend. Helpful are also the 41 CRAN Task Views listing packages by topic together with a short description.
However, these lists are maintained by volunteers and are not necessarily up to date:
PowerTOST6 and replicateBE7 are listed in the Task View Clinical Trial Design, Monitoring, and Ana­ly­sis, whereas Power2Stage8 and randomizeBE9 are not.

Before you download/install a certain package, I recommend to access its site at CRAN. The URL of packages has this pattern:
https://cran.r-project.org/package=foo, where foo is the name of the package. Inspect its ‘Reference Manual’ and possibly its ‘Vignettes’ to decide whether it will serve your purposes.

You can also try a package out in the browser. Say, you want to estimate the sample size for Average Bio­equi­valence with Expanded Limits (ABEL), an assumed within-subject Coefficient of Variation (CV) of 0.40 and a Test/Reference-ratio (theta0) of 0.90. The study should be performed in a 2-sequence, 4-period full replicate design (e.g., TRTR|RTRT) to achieve a power of at least 0.80. The package PowerTOST supports that.
Navigate to its R Package Documentation and in the text area change
help(PowerTOST)
to
sampleN.scABEL(CV = 0.40, theta0 = 0.90,
               design = "2x2x4", targetpower = 0.80)
Click below on

to get

+++++++++++ scaled (widened) ABEL +++++++++++
Sample size estimation
(simulation based on ANOVA evaluation)
---------------------------------------------
Study design: 2x2x4 (4 period full replicate)
log-transformed data (multiplicative model)
1e+05 studies for each step simulated.
alpha  = 0.05, target power = 0.8
CVw(T) = 0.4; CVw(R) = 0.4
True ratio = 0.9
ABE limits / PE constraint = 0.8 ... 1.25
EMA regulatory settings
- CVswitch            = 0.3
- cap on scABEL if CVw(R) > 0.5
- regulatory constant = 0.76
- pe constraint applied
Sample size search
n     power
26   0.7587
28   0.7829
30   0.8066

## Installation

Once you found a package suitable for you task there are two options:

1. If you have local administrative privileges (i.e., R is installed at
C:\Program Files\R\R-x.y.z), right-click on the desktop shortcut and select Run as Administrator, provide your password, and continue as described below.
2. If not, click on the desktop shortcut and continue as described below.

Open the R console and in the menu bar click on Packages → Install package(s)….

A window with a list of CRAN mirrors opens:

I suggest to keep the default. The 0-Cloud is hosted by RStudio and will initiate the download from a mirror close to you. Furthermore, it counts downloads, which is nice to know for the developers of packages (see the badges of PowerTOST on GitHub).

The next list is very long, since it contains all packages.

Scroll down to the one you want to install and click .
If you want to install more than one, use -click on each and confirm you selection with at the end.

As an example installing the package Power2Stage:8

Note that the ZIP-file comes with an MD5 checksum, which verifies the content. If you get an error, something went wrong in the download. Try it again.

Some packages depend10 on others.
Example for Power2Stage: It depends on the packages PowerTOST,6mvtnorm,11 and cubature.12 PowerTOST depends on TeachingDemos13 and cubature on Rcpp.14 Hence, in a new installation of Power2Stage five other packages will be installed as well. That’s not shown in the screenshot above because I have them already installed.

Now you can attach the library and show its manual in the browser.

library(Power2Stage)
help(p=Power2Stage)

## Update

It’s good practice to check regularly whether packages are updated. Whereas some ‘mature’ packages are considered stable by its maintainer and are updated maybe just once a year, others might be updated once a month.

To check whether your packages are up to date:

old.packages()

After specifying the mirror you will get a list showing the installed versions and the ones on the repository. However, it does not tell whether the Windows-binaries (the ZIP-files) have already been built. You need special tools to build a package from the source-code. That’s not for beginners.

If you are as lazy as I am, you can automatically update all your outdated libraries:

update.packages(checkBuilt = TRUE, ask = FALSE)

Likely your list will be shorter (I have 900+ packages installed on my machines). Once the source code of a package is available, it takes up to one week till the Windows-binaries (the ZIP-files) are built on CRAN. That’s for experts and therefore, in the next window

click on the central button (the buttons will be labeled in your locale; on my German Windows means ‘No’).

Only the Windows-binaries will be installed.

## Issues

Some packages require a minimum release of R (e.g., replicateBE7 depends on R ≥ 3.5.0). Given, quite old (published in April 2018). Hence, if you have such an outdated release, installation of a package requiring a later release will fail.

Therefore, update R first (see below) and then the package.

## Deinstallation

remove.packages("foo")

where foo is the package you want to deinstall. Note that this command does not deinstall dependent packages. That’s by design because other packages might still need them.

# Update 🇷

R is quite mature; it was originally developed by Ross Ihaka and Robert Gentleman in 1992.15 The first release was published in December 1997 and new versions are published every couple of months.

library(rversions)
rv                              <- r_versions()
rv$nickname[is.na(rv$nickname)] <- "none"
rv$date <- strftime(rv$date, format = "%Y-%m-%d")
rv                              <- rv[order(rv\$date, decreasing = TRUE), ]
print(rv, row.names = FALSE, right = FALSE)
cat("1st digit: major release",
"\n2nd digit: minor release",
"\n3rd digit: patch")
#  version date       nickname
#  4.2.2   2022-10-31 Innocent and Trusting
#  4.2.1   2022-06-23 Funny-Looking Kid
#  4.2.0   2022-04-22 Vigorous Calisthenics
#  4.1.3   2022-03-10 One Push-Up
#  4.1.2   2021-11-01 Bird Hippie
#  4.1.1   2021-08-10 Kick Things
#  4.1.0   2021-05-18 Camp Pontanezen
#  4.0.5   2021-03-31 Shake and Throw
#  4.0.4   2021-02-15 Lost Library Book
#  4.0.3   2020-10-10 Bunny-Wunnies Freak Out
#  4.0.2   2020-06-22 Taking Off Again
#  4.0.1   2020-06-06 See Things Now
#  4.0.0   2020-04-24 Arbor Day
#  3.6.3   2020-02-29 Holding the Windsock
#  3.6.2   2019-12-12 Dark and Stormy Night
#  3.6.1   2019-07-05 Action of the Toes
#  3.6.0   2019-04-26 Planting of a Tree
#  3.5.3   2019-03-11 Great Truth
#  3.5.2   2018-12-20 Eggshell Igloo
#  3.5.1   2018-07-02 Feather Spray
#  3.5.0   2018-04-23 Joy in Playing
#  3.4.4   2018-03-15 Someone to Lean On
#  3.4.3   2017-11-30 Kite-Eating Tree
#  3.4.2   2017-09-28 Short Summer
#  3.4.1   2017-06-30 Single Candle
#  3.4.0   2017-04-21 You Stupid Darkness
#  3.3.3   2017-03-06 Another Canoe
#  3.3.2   2016-10-31 Sincere Pumpkin Patch
#  3.3.1   2016-06-21 Bug in Your Hair
#  3.3.0   2016-05-03 Supposedly Educational
#  3.2.5   2016-04-14 Very, Very Secure Dishes
#  3.2.4   2016-03-10 Very Secure Dishes
#  3.2.3   2015-12-10 Wooden Christmas-Tree
#  3.2.2   2015-08-14 Fire Safety
#  3.2.1   2015-06-18 World-Famous Astronaut
#  3.2.0   2015-04-16 Full of Ingredients
#  3.1.3   2015-03-09 Smooth Sidewalk
#  3.1.2   2014-10-31 Pumpkin Helmet
#  3.1.1   2014-07-10 Sock it to Me
#  3.1.0   2014-04-10 Spring Dance
#  3.0.3   2014-03-06 Warm Puppy
#  3.0.2   2013-09-25 Frisbee Sailing
#  3.0.1   2013-05-16 Good Sport
#  2.15.3  2013-03-01 Security Blanket
#  2.15.2  2012-10-26 Trick or Treat
#  2.15.1  2012-06-22 Roasted Marshmallows
#  2.15.0  2012-03-30 Easter Beagle
#  2.14.1  2011-12-22 December Snowflakes
#  2.14.0  2011-10-31 Great Pumpkin
#  2.13.2  2011-09-30 none
#  2.13.1  2011-07-08 none
#  2.13.0  2011-04-13 none
#  2.12.2  2011-02-25 none
#  2.12.1  2010-12-16 none
#  2.12.0  2010-10-15 none
#  2.11.1  2010-05-31 none
#  2.11.0  2010-04-22 none
#  2.10.1  2009-12-14 none
#  2.10.0  2009-10-26 none
#  2.9.2   2009-08-24 none
#  2.9.1   2009-06-26 none
#  2.9.0   2009-04-17 none
#  2.8.1   2008-12-22 none
#  2.8.0   2008-10-20 none
#  2.7.2   2008-08-25 none
#  2.7.1   2008-06-23 none
#  2.7.0   2008-04-22 none
#  2.6.2   2008-02-08 none
#  2.6.1   2007-11-26 none
#  2.6.0   2007-10-03 none
#  2.5.1   2007-06-28 none
#  2.5.0   2007-04-24 none
#  2.4.1   2006-12-18 none
#  2.4.0   2006-10-03 none
#  2.3.1   2006-06-01 none
#  2.3.0   2006-04-24 none
#  2.2.1   2005-12-20 none
#  2.2.0   2005-10-06 none
#  2.1.1   2005-06-20 none
#  2.1.0   2005-04-19 none
#  2.0.1   2004-11-15 none
#  2.0.0   2004-10-04 none
#  1.9.1   2004-06-21 none
#  1.9.0   2004-04-12 none
#  1.8.1   2003-11-21 none
#  1.8.0   2003-10-08 none
#  1.7.1   2003-06-16 none
#  1.7.0   2003-04-16 none
#  1.6.2   2003-01-10 none
#  1.6.1   2002-11-01 none
#  1.6.0   2002-10-01 none
#  1.5.1   2002-06-17 none
#  1.5.0   2002-04-29 none
#  1.4.1   2002-01-30 none
#  1.4     2001-12-19 none
#  1.3.1   2001-08-31 none
#  1.3     2001-06-22 none
#  1.2.3   2001-04-26 none
#  1.2.2   2001-02-26 none
#  1.2.1   2001-01-15 none
#  1.2     2000-12-15 none
#  1.1.1   2000-08-15 none
#  1.1     2000-06-15 none
#  1.0.1   2000-04-14 none
#  1.0     2000-02-29 none
#  0.99    2000-02-07 none
#  0.90.1  1999-12-15 none
#  0.90    1999-11-22 none
#  0.65.1  1999-10-06 none
#  0.65    1999-08-27 none
#  0.64.2  1999-07-02 none
#  0.64.1  1999-05-07 none
#  0.64    1999-04-07 none
#  0.63.3  1999-03-05 none
#  0.63.2  1999-01-11 none
#  0.63.1  1998-12-04 none
#  0.63    1998-11-13 none
#  0.62.4  1998-10-23 none
#  0.62.3  1998-08-28 none
#  0.62.2  1998-07-10 none
#  0.62.1  1998-06-15 none
#  0.62    1998-06-14 none
#  0.61.3  1998-05-02 none
#  0.61.2  1998-03-14 none
#  0.61.1  1998-01-10 none
#  0.61    1997-12-21 none
#  0.60    1997-12-04 none
# 1st digit: major release
# 2nd digit: minor release
# 3rd digit: patch

Changes are described in the R News (see the current one).

At the latest when you attach an updated library (say, foo), you will get a warning:

Warning message:
package ‘foo’ was built under R version x.y.z

If x.y.z is higher than your version of R, its high time to update it.

First of all download and install the new release as described above. The installer will suggest to install to a folder with a different release-number than the one you have. Accept that (you can have different versions installed in parallel).

Navigate to the old installation’s sub-folder etc. Copy the file Rconsole (and Rprofile.site if you edited it) to the corresponding one in the new installation.

Once you have done that, navigate to your old installation and copy the entire library folder. Navigate to the new installation and paste it (i.e., overwrite its entire content).

Click (right-click if you have administrative privileges) the desktop shortcut of the new version and update all libraries as described above.

• You can keep different versions of R installed in parallel. That’s generally only required if a package was archived16 because it was not compatible with a later version and you still want to use it. An example is package bear,17 which requires 4.1.x for installation.18

There is a drawback of keeping different versions. Files in R’s native binary format .Rdata will always open in the latest version (unless you prevented saving the version number in the registry in Installation step 6 of all versions).

• If you don’t want to keep the previous version, navigate to the old installation and execute the file unins000.exe to remove it (including its desktop shortcut). However, the library folder will not be removed. Delete it, navigate one level up and delete the R-x.y.z folder as well.

# IDEs

In many companies the Integrated Development Environment RStudio is used. My personal views of its pros and cons:

• Pros
• Automatic completion of arguments, spell and syntax check. Great if you notoriusly – like me – type TREU19 instead of TRUE.
• Straightforward installation and update of packages.
• Support of the wonderful R Markdown, knitr, and pandoc.
• Tools to build own packages with version control (locally and on GitHub)… I use it regularly myself.
• Cons
• The graphics window is not optimal. See this example.
• Whereas in Base R you can only have one version of a package installed, in RStudio you can keep different ones. Depending on the setup, it is possible that the first (which is not the most current one) will be used. This might lead to confusion.20
• Unless you develop packages, IMHO, it’s just over the top.

An alternative for neRds is Tinn-R.

# Validation

See this document21 about the acceptability of Base R.

Validation of any software (yes, of SAS as well…) lies in the hands of the user.22 23 Many packages contain test-scripts supporting users in validating their installations.
Generally in the respective ‘NEWS’-file the development of the package, bug-fixes, and introduction of new methods is documented (examples: PowerTOST, Power2Stage, replicateBE).

As an aside, statisticians of the U.S. FDA regularly use R themselves…

Helmut Schütz 2022
R and rversions GPL 3.0, klippy MIT, pandoc GPL 2.0.
1st version April 13, 2021. Rendered November 1, 2022 10:59 CET by rmarkdown via pandoc in 0.60 seconds.

### Footnotes and References

1. Csárdi G, Ooms J, R Consortium. rversions: Query ‘R’ Versions, Including ‘r-release’ and ‘r-oldrel’. Package version 2.1.2. 2022-08-31. CRAN.↩︎

2. Kurt Hornik and the R Core Team. R FAQ. Frequently Asked Questions on R. R Basics 2022-10-31. Online.↩︎

3. AFAIK, the package PowerTOST is the only software supporting sample size estimations for reference-scaling in bioequivalence out of the box. Good luck developing your own code in SAS or MatLab.↩︎

4. Maslow A. The Psychology of Science: A Reconnaissance. 1966. Ch. 2, p. 15.↩︎

5. I recommend to run R in English. Given its hundreds of thousands of users it will be much easier to obtain qualified help if you get warnings and error messages in the nowadays lingua franca of science.↩︎

6. Labes D, Schütz H, Lang B. PowerTOST: Power and Sample Size for (Bio)Equivalence Studies. Package version 1.5.4.9000. 2022-04-25. CRAN.↩︎

7. Schütz H, Tomashevskiy M, Labes D. replicateBE: Average Bioequivalence with Expanding Limits (ABEL). Package version 1.1.3. 2022-05-02. CRAN.↩︎

8. Labes D, Lang B, Schütz H. PowerTOST: Power2Stage: Power and Sample-Size Distribution of 2-Stage Bio­equi­va­lence Studies. Package version 0.5.4.9000. 2022-07-02. CRAN.↩︎

9. Labes D. randomizeBE: Create a Random List for Crossover Studies. Package version 0.3.5. 2019-08-24. CRAN.↩︎

10. They import functions which are exported by other packages.↩︎

11. Genz A, Bretz F, Miwa T, Mi X, Leisch F, Scheipl F, Bornkamp B, Maechler M, Hothorn T. mvtnorm: Multi­vari­ate Normal and t Distributions. Package version 1.1.3. 2021-10-05. CRAN.↩︎

12. Narasimhan B, Koller M, Johnson SG, Hahn T, Bouvier A, Kiêu K. cubature: Adaptive Multivariate Integration over Hypercubes. Package version 2.0.4.5. 2022-08-16. CRAN.↩︎

13. Snow G. TeachingDemos: Demonstrations for Teaching and Learning. Package version 2.12. 2020-04-01. CRAN.↩︎

14. Eddelbuettel D, Francois R, Allaire JJ, Ushey K, Kou Q, Russell N, Ucar I, Bates D, Chambers J. Rcpp: Seam­less R and C++ Integration. Package version 2.0.4.5. 2022-08-16. CRAN.↩︎

15. Ihaka R, Gentleman R. R: A Language for Data Analysis and Graphics. J Comput Graph Stat. 1996; 5(3): 299–314 doi:10.2307/1390807.↩︎

16. CRAN Archive. Online.↩︎

17. Lee, H-y, Lee Y-j. bear: Data Analysis Tool for Average Bioequivalence and Bioavailability. Package version 2.9.0. 2021-04-20. Online.↩︎

18. However, it is possible to use it on R > 4.1.3. For the procedure of the package ivivc of the same authors see this post at the BEBA Forum.↩︎

19. That’s a false friend. In German »treu« means »faithful, loyal«, whereas the English »true« translates to German »wahr, richtig«.↩︎

20. Once I visited one of my clients to demonstrate how to estimate the sample size for the EMA’s method of reference scaling in PowerTOST. RStudio, of course. When I tried
sampleN.scABEL(CV = 0.45)
I was slapped in the face with
Error in sampleN.scABEL(CV = 0.45) :
could not find function "sampleN.scABEL"
Updating PowerTOST didn’t help. It turned out that RStudio still used v1.0-00 of October 2012 (‼), where this function was not implemented…↩︎

21. The R Foundation for Statistical Computing. A Guidance Document for the Use of R in Regulated Clinical Trial Environments. Vienna. October 18, 2021. online.↩︎

22. FDA. Statistical Software Clarifying Statement. May 6, 2015.  Internet Archive.↩︎

23. WHO. Guidance for organizations performing in vivo bioequivalence studies. Geneva. May 2016. Technical Report Series No. 996, Annex 9. Section 4. Online.↩︎