Consider allowing JavaScript. Otherwise, you have to be proficient in reading LaTeX since formulas will not be rendered. Furthermore, 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 generated with R 4.0.5.

See also a collection of other articles.

  • Click to show / hide R code.

Introduction

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 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 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:

  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 you organization’s policy does not even allow that, you have to convince it that it’s simply necessary to do your job.
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 the first place:

    1. Make clear that even a most simple task (which may take you a minute) has to be outsourced. CDAs, paperwork to and fro, ridiculous consultants’ fees, etc.
      If this argument helps, return to step 1 or 2.
    2. If not, consider to find another employer (not wearing a tin foil hat).

top of section ↩︎

Download and Installation

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 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).2
    After accepting the license, you will be asked for the location.

Fig. 1 Installation step 1.1

  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.

Fig. 2 Installation step 2.1.

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.
After accepting the license, you will be asked for the location.

Fig. 3 Installation step 2.2.

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. It saves more than 50 MB of disk space since the 32-bit Files are not needed on a 64 bit Windows.

Fig. 4 Installation step 3.

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

Fig. 5 Installation step 4.

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

Fig. 6 Installation step 5.

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.

Fig. 7 Installation step 6.

Hopefully the next window will look like this one:

Fig. 8 Completed Installation.

top of section ↩︎ previous section ↩︎

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)

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

Fig. 9 R Console.

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:

Fig. 10 GUI Configuration.

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

top of section ↩︎ previous section ↩︎

Packages, Libraries

There is some confusion about terminology.

  1. 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.

  2. A library is a package already installed on your machine.
    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:
PowerTOST and replicateBE are listed in the Task View Clinical Trial Design, Monitoring, and Analysis, whereas Power2Stage and 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:
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 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
help(PowerTOST)
to
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

top of section ↩︎ previous section ↩︎

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 Adminstrator, 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:

Fig. 11 Top of list of CRAN mirrors.

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.

Fig. 12 Top of list of packages.

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

As an example installing the package Power2Stage:

Fig. 13 Successful installation.

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 depend3 on others.
Example for Power2Stage: It depends on the packages PowerTOST, mvtnorm, and cubature. PowerTOST depends on TeachingDemos and cubature 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.

library(Power2Stage)
help(p=Power2Stage)

Fig. 14 Attach and help.

top of section ↩︎ previous section ↩︎

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)

Fig. 15 Update information.

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

Fig. 16 Load and help.

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

Only the Windows-binaries will be installed.

top of section ↩︎ previous section ↩︎

Issues

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.

top of section ↩︎ previous section ↩︎

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.

top of section ↩︎ previous section ↩︎

Update R

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:

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 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).

However, the library folder will not be removed. Delete it, navigate one level up and delete the R-x.y.z folder as well.

top of section ↩︎ previous section ↩︎

IDEs

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

  • Pros
    • Automatic completion of arguments and syntax checking. Great if you notoriusly – like me – type TREU4 instead of TRUE.
    • Straightforward installation and update of packages.
    • Tools to build own packages, support of the wonderful R Markdown, version control (locally and on Github)… I use it myself regularly.
  • 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.5
    • Unless you develop packages, IMHO, it’s just over the top.

An alternative for neRds is Tinn-R.

top of section ↩︎ previous section ↩︎

Validation

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…

top of section ↩︎ previous section ↩︎

License

CC BY 4.0 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


  1. Kurt Hornik. R FAQ. Frequently Asked Questions on R. 2020-02-20. R Basics.↩︎

  2. 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’.↩︎

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

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

  5. 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"
    Updating PowerTOST didn’t help. It turned out that RStudio still used v1.0-0 of October 2012 (‼) where this function was not implemented…↩︎

  6. The R Foundation for Statistical Computing. March 25, 2018. A Guidance Document for the Use of R in Regulated Clinical Trial Environments..↩︎