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.4.2 on Windows 7 build 7601, Service Pack 1,
Universal C Runtime 10.0.10240.16390 and package
rversions
.1
R
code.
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:
R
toC:\Program Files
. For details see below.R
to the default user location, which
isC:\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.
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:
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).5R-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.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.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:
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 30px 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 version 4.4.2 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")
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 October
2024 more than 21,600), Bioconductor,
GitHub, SOURCEFORGE, …
Pre-compiled packages can be downloaded as ZIP-files.
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.
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
6 and replicateBE
7 are listed in the Task
View Clinical
Trial Design, Monitoring, and Analysis, whereas
Power2Stage
8 and randomizeBE
9 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.
PowerTOST
supports that.help(PowerTOST)
sampleN.scABEL(CV = 0.40, theta0 = 0.90,
design = "2x2x4", targetpower = 0.80)
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 ↩︎
Once you found a package suitable for you task there are two options:
R
is installed atC:\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.Open the R
console and in the menu bar click on
Packages
→ Install package(s)…
.
A window with a list of the 95 (with June 2024) CRAN mirrors opens:
I suggest to keep the default. The 0-Cloud
is hosted by
Posit 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
cubature
, which itself depends on Rcpp
.13 Hence,
in a new installation of Power2Stage
four 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)
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 – if there are more recent ones
(otherwise, you get just NULL
). 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 (requiring the GNU compilers for C, C++, and Fortran). 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
7 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.
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.
R
is quite mature; it was
originally developed by Ross Ihaka and Robert
Gentleman in 1992.14 The first release was published in
December 1997 and new versions are published every few months.
library(rversions)
<- 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), ]
rv print(rv, row.names = FALSE, right = FALSE)
cat("1st digit: major release",
"\n2nd digit: minor release",
"\n3rd digit: patch")
# version date nickname
# 4.4.2 2024-10-31 Pile of Leaves
# 4.4.1 2024-06-14 Race for Your Life
# 4.4.0 2024-04-24 Puppy Cup
# 4.3.3 2024-02-29 Angel Food Cake
# 4.3.2 2023-10-31 Eye Holes
# 4.3.1 2023-06-16 Beagle Scouts
# 4.3.0 2023-04-21 Already Tomorrow
# 4.2.3 2023-03-15 Shortstop Beagle
# 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
# 3.0.0 2013-04-03 Masked Marvel
# 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.2 2012-02-29 Gift-Getting Season
# 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.
R
installed in parallel. That’s
generally only required if a package was archived15 because it was not
compatible with a later version and you still want to use it. An example
is package bear
,16 which requires 4.1.x for
installation.17There 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).
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.In many companies the Integrated Development Environment RStudio is used. My personal views of its pros and cons:
TREU
18 instead of
TRUE
.knitr
,19 and pandoc.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.20An alternative for neRds is Tinn-R.
See R’s Software Development Life Cycle21 and its bug-tracking system.22 See also this document23 about the acceptability of Base R in regulated environments. Note that ultimate responsibility for validation of any software (yes, of SAS as well…) lies in the hands of the user.24 25 26
Generally in the respective ‘NEWS’-file the development of the package, bug-fixes, and introduction of new methods is documented (examples: PowerTOST, Power2Stage, replicateBE). Many packages contain test-scripts supporting users in validating their installations. The man-pages of packages contain examples of functions with expected results. Some packages contain vignettes with more detailed examples (examples: PowerTOST, replicateBE).
As an aside, statisticians of the U.S. FDA regularly use R
themselves…
top of section ↩︎ previous section ↩︎
Helmut Schütz 2024
R
, rversions
, and
pandoc
GPL 3.0,
klippy
MIT.
1st version April 13, 2021. Rendered November 1, 2024 10:53
CET by rmarkdown via pandoc in 0.70 seconds.
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.↩︎
Kurt Hornik and the R Core Team. R FAQ. Frequently Asked Questions on R. R Basics 2024-10-31. Online.↩︎
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.↩︎
Maslow A. The Psychology of Science: A Reconnaissance. 1966. Ch. 2, p. 15.↩︎
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.↩︎
Labes D, Schütz H, Lang B. PowerTOST: Power and Sample Size for (Bio)Equivalence Studies. Package version 1.5.6. 2024-03-18. CRAN.↩︎
Schütz H, Tomashevskiy M, Labes D. replicateBE: Average Bioequivalence with Expanding Limits (ABEL). Package version 1.1.3. 2022-05-02. CRAN.↩︎
Labes D, Lang B, Schütz H. PowerTOST: Power2Stage: Power and Sample-Size Distribution of 2-Stage Bioequivalence Studies. Package version 0.5.4. 2021-11-20. CRAN.↩︎
Labes D. randomizeBE: Create a Random List for Crossover Studies. Package version 0.3.6. 2023-08-19. CRAN.↩︎
They import functions which are exported by other packages.↩︎
Genz A, Bretz F, Miwa T, Mi X, Leisch F, Scheipl F, Bornkamp B, Maechler M, Hothorn T. mvtnorm: Multivariate Normal and t Distributions. Package version 1.3.1. 2024-09-02. CRAN.↩︎
Narasimhan B, Koller M, Johnson SG, Hahn T, Bouvier A, Kiêu K. cubature: Adaptive Multivariate Integration over Hypercubes. Package version 2.1.1. 2024-07-11. CRAN.↩︎
Eddelbuettel D, Francois R, Allaire JJ, Ushey K, Kou Q, Russell N, Ucar I, Bates D, Chambers J. Rcpp: Seamless R and C++ Integration. Package version 2.1.1. 2024-07-11. CRAN.↩︎
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.↩︎
Lee, H-y, Lee Y-j. bear: Data Analysis Tool for Average Bioequivalence and Bioavailability. Package version 2.9.1. 2022-04-03. Online.↩︎
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.↩︎
That’s a false friend. In German »treu« means »faithful, loyal«, whereas the English »true« translates to German »wahr, richtig«.↩︎
Xie Y, et al. knitr: A General-Purpose Package for Dynamic Report Generation in R. Package version 1.48. 2024-07-05. CRAN.↩︎
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 (‼), when this function was not
implemented…↩︎
The R Foundation for Statistical Computing. R: Software Development Life Cycle. A Description of R’s Development, Testing, Release and Maintenance Processes. Vienna. October 18, 2021. Online.↩︎
The R Foundation for Statistical Computing. A Guidance Document for the Use of R in Regulated Clinical Trial Environments. Vienna. October 18, 2021. Online.↩︎
ICH. Statistical Principles for Clinical Trials. E9. 5 February 1998. Section 5.8. Online.↩︎
FDA. Statistical Software Clarifying Statement. Silver Spring. May 6, 2015. Online.↩︎
WHO. Guidance for organizations performing in vivo bioequivalence studies. Geneva. May 2016. Technical Report Series No. 996, Annex 9. Section 4. Online.↩︎