This article was generated with 4.0.5.
See also a collection of other articles.
There are excellent resources available on the net, esp. the R FAQ.1 However, for beginners or occasional users it might be too technical.
I’m assuming that you are running a 64 bit version of Windows (Windows 7 or later). If in doubt, right-click on
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 OS because you will be limited to 4 GB of memory – irrespective of how much RAM is installed on your machine.
There are four possible scenarios:
C:\Program Files. For details see below.
C:\Users\UserName\AppData\Roaming. For details see below.
“I suppose it is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail.
If you are not successful in the first place:
Navigate to CRAN’s download site for Windows and click on the first link
Download R x.y.z for Windows (where
x.y.z is always the latest 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
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).2
R-x.y.z-win.exeand you will be asked by the installer which language should be used during the installation. An information window appears.
Rdata. Whilst you can still store/load data in this format, doubleclicking on such a file will not work.
UserNameto 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. 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.
Hopefully the next window will look like this one:
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)
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
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).
You can change any setting during an interactive session. That’s sometimes needed when you share your screen in a video conference.
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, and may contain data, test-scripts, custom documentation, and/or vignettes giving background information and more detailed examples.
Packages are hosted on CRAN (with April 2021 more than 17,400), Bioconductor, GitHub, SOURCEFORGE,…
Packages can be downloaded as ZIP-files.
Installation not from CRAN may require tools to built a package from the source code (provided in gzip-format) and is out of scope of this article.
A library is a package already installed on your machine.
Before you can use it, you have to
attach it by executing the command
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:
replicateBE are listed in the Task View Clinical Trial Design, Monitoring, and Analysis, whereas
randomizeBE are not.
Before you download/install a certain package I recommend to access its site at CRAN. The URL of packages has this pattern:
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 Bioequivalence 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 at the bottom change
sampleN.scABEL(CV = 0.40, theta0 = 0.90,
design = "2x2x4", targetpower = 0.80)
Click on the green button below 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
Once you found a package suitable for you task there are two options:
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 Adminstrator, provide your password, and continue as described below.
If not, click on the desktop shortcut and continue as described below.
Open the R console and in the menu bar click on
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. However, 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
Some packages depend3 on others.
Power2Stage: It depends on the packages
PowerTOST depends on
Rcpp. 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.
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:
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 almost 800 packages installed on my machine). 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.
Some packages require a minimum release of R (e.g.,
replicateBE 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.
R itself is updated every couple of months. Changes are described in the R News (see e.g., the one for R 4.0.5).
At the latest when you attach an updated library (say,
foo), you will get a warning:
package ‘foo’ was built under R version x.y.z
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 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.
If you don’t want to keep the old version (generally only nerRs will), navigate to the old installation and execute the file
unins000.exe to remove the old version (including its desktop shortcut).
library folder will not be removed. Delete it, navigate one level up and delete the
R-x.y.z folder as well.
TREU4 instead of
An alternative for neRds is Tinn-R.
See this document6 about the acceptability of Base R.
Validation of any software (yes, of SAS as well…) lies in the hands of the user. 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.
Of note, statisticians of the U.S. FDA use R regularly themselves…
Helmut Schütz 2021
1st version April 13, 2021.
Rendered 2021-05-03 13:53:15 CEST by rmarkdown in 0.44 seconds.
Footnotes and References
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 nowadays lingua franca of science, ‘Bad English’.↩︎
They import functions which are exported by other packages.↩︎
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, design = "2x2x4") I was slapped in the face with
Error in sampleN.scABEL(CV = 0.45) :
could not find function "sampleN.scABEL"
PowerTOST didn’t help. It turned out that RStudio still used v1.0-0 of October 2012 (‼) where this function was not implemented…↩︎
The R Foundation for Statistical Computing. March 25, 2018. A Guidance Document for the Use of R in Regulated Clinical Trial Environments..↩︎