Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

R (4.6)  Module 1 – Start here: R, the console and a working setup

What R is and why researchers use it

What R is: a language and environment for statistics, its packages from base R to CRAN and Bioconductor, when to choose it, its versions and how to cite it.

  • Beginner
  • 10 minutes
  • Examples run with R 4.6.1 and Python 3.14.8
  • By MySmartCoPilot
Free lesson, Pro answers: 10 minutes
Free: the whole lesson. With a pass: the model answers to its 2 interview questions.

What you will learn

  • Describe what base R, the recommended packages, CRAN and Bioconductor each provide
  • Choose between R, Python, a spreadsheet and SQL for a step of a research project
  • Read an R version number and compare versions with getRversion()
  • Cite R in a paper with citation(), including its DOI
What you’ll learn

What you will learn

  • Describe what base R, the recommended packages, CRAN and Bioconductor each provide
  • Choose between R, Python, a spreadsheet and SQL for a step of a research project
  • Read an R version number and compare versions with getRversion()
  • Cite R in a paper with citation(), including its DOI
On this page

Eight volunteers took a reaction-time test twice, once after a normal night’s sleep and once after a short night. Did the short night slow them down, and by how much? In R the answer takes two lines, mean() for the average slowdown and t.test() for the test, and it comes with a confidence interval and a p-value.

R is a programming language made for questions like this, with an environment around it of packages, help pages and graphics. Below you will see what an R installation holds and where the rest of its packages come from, when R is the right tool and when another tool fits better, how to read the version you are running, and how to cite R when your numbers go into a paper.

R answers a statistical question in a few lines

Here are the eight volunteers in R. c() combines the numbers into a vector, one object that holds all eight, <- gives it a name, and the last two lines ask the questions. Lines that start with # are comments, which R skips:

Eight volunteers, two nights R · first_look.R
# Reaction times in milliseconds of eight volunteers, measured once after a
# normal night's sleep and once after a short night (a small made-up sample).
rested <- c(251, 238, 276, 262, 245, 289, 270, 255)
short_night <- c(268, 249, 301, 271, 262, 310, 284, 269)

# How much slower each volunteer was, on average, and a paired t-test.
mean(short_night - rested)
t.test(short_night, rested, paired = TRUE)

R ran the file and printed two answers:

first_look.R, run with R 4.6.1 Python · first_look_session.py
from session import run, version

version()
run("""
Rscript first_look.R
""")

Output

# R version 4.6.1 -- "Happy Hop"
$ Rscript first_look.R
[1] 16

	Paired t-test

data:  short_night and rested
t = 8.6863, df = 7, p-value = 5.37e-05
alternative hypothesis: true mean difference is not equal to 0
95 percent confidence interval:
 11.64443 20.35557
sample estimates:
mean difference 
             16 

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 first_look_session.py

The first line, [1] 16, is the average slowdown: after the short night the volunteers were 16 milliseconds slower, on average. Below it, one call to t.test() reports a whole analysis: the test statistic t = 8.6863 with 7 degrees of freedom, a p-value of 0.0000537 (printed as 5.37e-05), and a 95 percent confidence interval for the slowdown from about 11.6 to 20.4 milliseconds. paired = TRUE makes the test work on each volunteer’s own difference, which is what two measurements of the same people call for.

That is the work R is made for. The R Project describes R as “a language and environment for statistical computing and graphics”: a programming language, plus a coherent system around it in which statistical methods come ready to use. Tests like this one, linear and generalised linear models, probability distributions and plots are part of every installation, so an analysis is a short script rather than a program written from scratch.

R started as an implementation of S, a language for data analysis that John Chambers and colleagues developed at Bell Laboratories; its first authors were Ross Ihaka and Robert Gentleman at the University of Auckland, and today the R Core Team develops it. Its licence, the GNU GPL in version 2 or 3, lets anyone use, study, change and share R at no cost, and it runs on Windows, macOS, Linux and other Unix-like systems.

Taking an editor for R

RStudio, Positron and VS Code are editors: they send your code to R and show what it prints. Installing one of them does not install R, and R works without any of them. The next lesson installs R first, then an editor.

T-Test Calculator Type the eight pairs into the paired test and compare its t and p-value with R's 8.6863 and 5.37e-05.

Checkpoint

Check: What R is, and a first analysis

  1. Question 1 of 2 mean(short_night - rested) printed [1] 16. What does the 16 say?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: Each volunteer was, on average, 16 milliseconds slower after the short night

    Subtracting one vector from the other gives the eight slowdowns, 17, 11, 25, 9, 17, 21, 14 and 14 milliseconds, and their mean is 128 / 8 = 16. The t-test on the next line reports the same 16 as its "mean difference".

  2. Question 2 of 2 Why does the example's t.test() call use paired = TRUE?

    Choose one answer.

    A hint

    Think about who was measured on the two nights.

    Show the answer: Question 2 of 2

    Answer: The same eight people were measured twice, so the test should work on each person's own difference

    Each value in short_night belongs to one value in rested: the same volunteer. A paired test works on those eight differences. Treating the two nights as unrelated groups would mix the differences between people into the test and answer another question.

Packages: some come with R, the rest from CRAN or Bioconductor

mean() and t.test() worked without any setup because they live in package: A bundle of R functions, data and help pages. It is installed once into a package library and attached to a session with library(). that R attaches when it starts. A package is a bundle of functions, data and help pages. Two groups come with an R installation:

  • The 14 base package: One of the 14 packages that are part of R itself, such as base, stats, utils and graphics. They carry R's own version number. are part of R: base, stats (where t.test() lives), graphics, utils and ten more.
  • The 15 recommended package: One of the 15 packages, such as MASS, Matrix, survival and mgcv, that every binary distribution of R installs alongside the base packages., among them MASS, Matrix, nlme, survival and mgcv, are, in the words of the R FAQ, “to be included in all binary distributions of R”, so R’s installers put them on your computer too.

R lists both groups itself. The last line of this file shows which packages are attached when a session starts:

The packages that come with R R · packages.R
# The packages that are part of R, and the recommended ones that every binary
# distribution of R adds.
pkgs <- tools::standard_package_names()
lengths(pkgs)
pkgs$base
pkgs$recommended

# A base package carries the version of R itself.
packageVersion("stats")

# The packages attached when R starts: their functions work without library().
search()
packages.R, run with R 4.6.1 Python · packages_session.py
from session import run, version

version()
run("""
Rscript packages.R
""")

Output

# R version 4.6.1 -- "Happy Hop"
$ Rscript packages.R
       base recommended 
         14          15 
 [1] "base"      "tools"     "utils"     "grDevices" "graphics"  "stats"    
 [7] "datasets"  "methods"   "grid"      "splines"   "stats4"    "tcltk"    
[13] "compiler"  "parallel" 
 [1] "MASS"       "lattice"    "Matrix"     "nlme"       "survival"  
 [6] "boot"       "cluster"    "codetools"  "foreign"    "KernSmooth"
[11] "rpart"      "class"      "nnet"       "spatial"    "mgcv"      
[1] ‘4.6.1’
[1] ".GlobalEnv"        "package:stats"     "package:graphics" 
[4] "package:grDevices" "package:utils"     "package:datasets" 
[7] "package:methods"   "Autoloads"         "package:base"     

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 packages_session.py

packageVersion("stats") prints 4.6.1: a base package carries the version of R itself. search() shows stats, graphics, grDevices, utils, datasets, methods and base: their functions work by name at once. An installed package that is not on that list, such as the recommended survival, has to be attached with library(survival) before its functions work by name.

Everything else comes from two archives. CRAN: The Comprehensive R Archive Network: a set of mirrored sites that carry R itself and the contributed packages that install.packages() installs., the Comprehensive R Archive Network, is a set of mirrored sites that carry R and more than 25,000 contributed packages; install.packages("name") copies one onto your computer. Its 50 task view: A CRAN page that lists and describes the packages for one topic, such as Bayesian statistics, econometrics or survival analysis. sort them by topic, from Bayesian statistics and clinical trials to econometrics, mixed models, survival analysis and time series. Bioconductor: An archive of R packages for genomics and biology, with one release for each R version. Its packages are installed with BiocManager::install(). is the archive for genomics and biology: its release 3.23, made for R 4.6, has 2,418 software packages, installed with the CRAN package BiocManager through BiocManager::install("name"). Follow a package from an archive to your session:

Packages come from CRAN and Bioconductor into the package library on your computer, and library() loads them into an R session.CRAN25,000+ packagesBioconductor2,418 packagesPackage libraryon your computer:14 base, 15 recommended,the rest you installYour R session:stats, utils and othersattached at startinstall.packages()BiocManager::install()library(name)

Where the packages of an R session come from

Text description of the diagram

The figure has two archives at the top, the package library on your computer in the middle and your R session at the bottom.

  1. CRAN holds more than 25,000 contributed packages. install.packages() copies one into your package library.
  2. Bioconductor 3.23, a release made for R 4.6, holds 2,418 software packages for biology. BiocManager::install() copies one into your package library.
  3. The package library already holds the 14 base packages and, with R's installers, the 15 recommended packages. The rest are the ones you installed.
  4. library(name) loads a package from the library into your R session. stats, graphics, utils and a few others are attached as soon as R starts, so their functions work at once.

Key idea

R’s core is small and its reach is wide: 14 base packages in every R, 15 recommended ones in every installer, and the rest from CRAN or Bioconductor, installed once and attached with library() in each session that uses them.

Checkpoint

Check: Base, recommended and contributed packages

  1. Question 1 of 2 In a fresh session, survfit() from the recommended package survival stops with "could not find function". R came from CRAN's installer. What is the fix?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: Run library(survival) first, because survival is installed but not attached when R starts

    search() showed what a session attaches by itself: stats, graphics, grDevices, utils, datasets, methods and base. survival is on the computer but not on that list, so library(survival) attaches it before its functions work by name.

  2. Question 2 of 2 Where do you look first for an R package that analyses gene-expression data?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: Bioconductor

    Genomics and other biology packages live on Bioconductor and install with BiocManager::install(). CRAN's task views are the place to look for most other topics.

Where R is the usual choice, and where another tool fits better

Four steps of one research project show why the answer is not always R: fitting a mixed model to repeated measurements of 120 patients; summing a year of transactions that live in a database; showing a model’s predictions inside a web app; fixing three typing errors in a 30-row table of field sites.

  • R fits the first. Its statistical methods are in base R and on CRAN, where task views list the packages for mixed models, survival analysis, econometrics and clinical trials, and Bioconductor does the same for genomics.
  • SQL fits the second. The database filters, joins and sums the rows where they live, even when the table is larger than a computer’s memory; R or Python then read the small result.
  • Python fits the third. Python.org describes it as a language that lets you “work quickly and integrate systems more effectively”, and its standard statistics module says it is “not intended to be a competitor” to third-party libraries, so statistical models come from add-on libraries.
  • A spreadsheet fits the fourth: a small table you can see and fix by hand. Once the same steps must run again on new data, a script is safer, because clicks leave no record of what was done.

Try it on a step of your own work. Answer the two questions, and the table marks the tools that fit, with a reason in every cell:

Interactive · answer and compare Which tool fits this research task? Answer two questions about one step of your work. Every tool is shown as it is until you answer, then the table marks the ones that fit and says why.
What is the main job of this step?
Will the same steps run again, on new or corrected data?

Answer the questions above: the table then marks what fits your case and says why the rest does not.

R, Python, a spreadsheet and SQL against four things a step of research can need
Tool Statistical models Rerun on new data Tables in a database Part of other software
R Good tests, linear and generalised models in base R; task views list specialised ones Good a script reruns every step, from the raw data to the figures Mixed reads what a query returns; the result must fit in memory Mixed can serve results as an app or an API, but is rarely the core of one
Python Mixed basic statistics built in; models come from add-on libraries Good a script reruns every step, from the raw data to the figures Mixed reads what a query returns; the result must fit in memory Good a general-purpose language, made to work with other systems
A spreadsheet Mixed functions for common statistics; specialised models need other tools Poor the steps are clicks and edits, so a rerun is done again by hand Poor made for a table you can see and edit, not for large tables Poor a file people open, not code other programs call
SQL in a database Poor counts, sums, averages and joins; models are fitted elsewhere Good a saved query reruns on whatever the tables hold now Good runs where the data lives, on tables larger than memory Mixed apps send it queries, but the app is written in another language
How the answers decide
  • “What is the main job of this step?” Fit or test a statistical model: rules out A spreadsheet and SQL in a database and adds a caveat to Python. Fitting and testing models is the work R was built for, with the methods in base R and on CRAN. Python does it with add-on libraries.
  • “What is the main job of this step?” Summarise rows that live in a database: rules out A spreadsheet and adds a caveat to R and Python. Let the database filter, join and sum the rows where they live. R or Python then read the much smaller result.
  • “What is the main job of this step?” Feed results into an app or a service: rules out A spreadsheet and adds a caveat to R. Code that must live inside other software suits a general-purpose language. R can still serve its results through an app or an API.
  • “What is the main job of this step?” Look at a small table and fix it by hand: adds a caveat to R, Python and SQL in a database. For one look at a small table, a spreadsheet is quickest. Write the steps as a script as soon as they must be repeated.
  • “Will the same steps run again, on new or corrected data?” Yes, again and again: rules out A spreadsheet. Steps done by clicking in cells are hard to repeat exactly. A script or a saved query runs the same steps on new data.

In short: R for models, tests and research graphics; SQL for large tables in a database; Python for analysis that must live inside other software; a spreadsheet for a quick look by hand. Many projects use two of them, such as SQL to cut a large table down and R to model what is left.

Checkpoint

Check: When R fits, and when another tool does

  1. Question 1 of 2 A study measured 120 patients at four visits each and must fit a mixed model with a random effect for each patient. Which tool fits this step?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: R

    Fitting and testing models is the work R was built for: the recommended package nlme fits mixed models, and CRAN's MixedModels task view lists many more.

  2. Question 2 of 2 A year of 200 million transactions lives in a database, and you need the total for each region and month. What is the sensible first step?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: Let SQL compute the totals in the database, then read the small result into R

    Cut the data down where it lives: a GROUP BY query returns one row per region and month, which R can then plot or model. Using two tools, each for what it does best, is common.

Versions: what the three numbers mean and why they matter

Every recorded run on these pages starts with the same line, R version 4.6.1 -- "Happy Hop". The three numbers are the major version 4, the minor version 6 and the patch level 1, and “Happy Hop” is the release’s nickname. R has one x.y.0 release a year, in spring, and patch releases such as 4.6.1 in between when they are needed. Inside R, getRversion() gives the version, and the list R.version holds its parts:

Which R is running? R · version.R
# Which R is running, and how R itself describes the version.
getRversion()
R.version$major
R.version$minor
R.version$nickname

# Compare versions as versions: as text, "4.10.0" sorts before "4.6.0".
getRversion() >= "4.6.0"
"4.10.0" > "4.6.0"
numeric_version("4.10.0") > numeric_version("4.6.0")
version.R, run with R 4.6.1 Python · version_session.py
from session import run, version

version()
run("""
Rscript version.R
""")

Output

# R version 4.6.1 -- "Happy Hop"
$ Rscript version.R
[1] ‘4.6.1’
[1] "4"
[1] "6.1"
[1] "Happy Hop"
[1] TRUE
[1] FALSE
[1] TRUE

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 version_session.py

R.version$minor is "6.1", the minor version and the patch level together, and like every part of R.version it is text. getRversion() returns a version object, so getRversion() >= "4.6.0" compares the numbers one part at a time and prints TRUE. Comparing the text instead goes wrong as soon as a part has two digits: the run shows that, as text, "4.10.0" > "4.6.0" is FALSE, because the character 1 sorts before 6.

Comparing version numbers as text

The wrong version is R.version.string >= "R version 4.1.0": two pieces of text, compared character by character, so a later 4.10 would sort before 4.6. The right one is getRversion() >= "4.1.0", or numeric_version() on both sides, which compares the numbers part by part: the run’s last line prints TRUE for 4.10.0 against 4.6.0.

The version matters because each release changes something a script can depend on. Walk through the releases of R 4:

Timeline · 8 events in order R 4, one x.y.0 release a year Walk through the releases of R 4 in order. Each one changed something a script can depend on, so the version you run matters.
  1. 4.0.0

    Text columns stay text new default

    data.frame() and read.table() no longer turn text into factors, because stringsAsFactors now defaults to FALSE. Raw strings such as r"(C:\data)" arrive too. A script written for R 3 can build factors where R 4 keeps text.

  2. 4.1.0

    The native pipe and short functions new syntax

    x |> f() passes x to f(), and \(x) x + 1 is short for function(x) x + 1. A script that uses either stops with a syntax error on R 4.0.

  3. 4.2.0

    Conditions of one value, and UTF-8 on Windows breaking change

    if() and while() with a condition of more than one value stop with an error instead of a warning. On recent Windows systems R uses UTF-8 as its native encoding, and 32-bit Windows builds are dropped.

  4. 4.3.0

    && and || take single values only breaking change

    Calling && or || with a side of more than one value is now always an error. Use & and | for element-by-element logic, or any() and all() to reduce a vector to one value.

  5. 4.4.0

    %||% joins base R new operator

    L %||% R gives L unless L is NULL, and R otherwise, with no package needed. is.atomic(NULL) now returns FALSE.

  6. 4.5.0

    grepv() and the penguins data new functions

    grepv() is grep() that returns the matching values themselves, and the datasets package gains penguins and penguins_raw to practise on.

  7. 4.6.0

    A DOI for R, and literal file patterns new

    The R citation now carries a DOI, 10.32614/R.manuals, and list.files() gains fixed = TRUE, which matches a pattern as plain text instead of a regular expression.

  8. 4.6.1

    A patch release of 4.6

    Patch releases come between the yearly ones when they are needed, and 4.6.1 is mostly bug fixes, so scripts written for 4.6.0 keep working. Every run in this track was made with 4.6.1.

The timeline has 8 events, from 4.0.0 to 4.6.1.

A script that uses |> needs R 4.1.0 or later, and one written for R 3 can build factors where R 4 keeps text. That is why a script states the oldest R it needs, and a methods section names the version that produced its numbers.

Checkpoint

Check: Reading and comparing R versions

  1. Question 1 of 2 On R 4.6.1, what does R.version$minor hold?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: The text "6.1"

    R.version$major is "4" and R.version$minor is "6.1". getRversion() gives the whole version as one version object, which is what comparisons should use.

  2. Question 2 of 2 What does this line print?

    Read the code, then choose one answer.

    "4.10.0" > "4.6.0"
    Show the answer: Question 2 of 2

    Answer: [1] FALSE

    The run printed FALSE for this line and TRUE for numeric_version("4.10.0") > numeric_version("4.6.0"). Compare versions with getRversion() or numeric_version(), never as text.

Citing R: citation() writes the reference for you

A paper whose numbers came from R says so, with the version. You do not have to write the reference yourself: citation() prints the one the R Core Team asks for, ready to paste, and a BibTeX entry for LaTeX users:

How to cite R R · cite.R
# How to cite R: the reference and a BibTeX entry, then the DOI on its own.
citation()
citation()$doi
cite.R, run with R 4.6.1 Python · cite_session.py
from session import run, version

version()
run("""
Rscript cite.R
""")

Output

# R version 4.6.1 -- "Happy Hop"
$ Rscript cite.R
To cite R in publications use:

  R Core Team (2026). _R: A Language and Environment for Statistical
  Computing_. R Foundation for Statistical Computing, Vienna, Austria.
  doi:10.32614/R.manuals <https://doi.org/10.32614/R.manuals>.
  <https://www.R-project.org/>.

A BibTeX entry for LaTeX users is

  @Manual{,
    title = {R: A Language and Environment for Statistical Computing},
    author = {{R Core Team}},
    organization = {R Foundation for Statistical Computing},
    address = {Vienna, Austria},
    year = {2026},
    doi = {10.32614/R.manuals},
    url = {https://www.R-project.org/},
  }

We have invested a lot of time and effort in creating R, please cite it
when using it for data analysis. See also ‘citation("pkgname")’ for
citing R packages.
[1] "10.32614/R.manuals"

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 cite_session.py

Since R 4.6.0 the reference carries a DOI, 10.32614/R.manuals, and citation()$doi returns it on its own, as the last line shows. The year in the reference is read from R.version$year, so it is always the release year of the R you run.

Packages are cited the same way. citation("name") prints the reference a package’s authors ask for, taken from its CITATION file or, when it has none, built from its DESCRIPTION file. A base package points back to R: citation("stats") says that stats is part of R and prints the R reference above. A methods section names R with its version, then each package that did real work, with its own version from packageVersion("name").

Checkpoint

Check: Citing R and its packages

  1. Question 1 of 2 Which expression returns the DOI of the R citation as a string?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: citation()$doi

    The last line of the run printed [1] "10.32614/R.manuals" for citation()$doi. The R citation has carried this DOI since R 4.6.0.

  2. Question 2 of 2 Your analysis used the survival package. Which call prints the reference its authors ask for?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: citation("survival")

    A methods section names R with its version, then each package that did real work with its own reference from citation("name") and its version from packageVersion("name").

Practise: what R is and where it fits

Once R is installed, in the next lesson, run getRversion() and citation() on your own computer and compare what they print with the runs above: the version may differ, and the reference follows it.

The session below asks up to twelve of this lesson’s fifteen questions, one at a time, on what R is, its packages, choosing a tool, versions and citations. Where you slip, it stays with that idea; where you are right, it asks something harder:

Practice that adapts to you

Practise this lesson

15 questions about 5 ideas of this lesson. Each answer is explained at once, and what you get right is kept in this browser.

  1. Question 1 of 15 How does the R Project describe R?

    Choose one answer.

    Show the answer: Question 1 of 15

    Answer: A language and environment for statistical computing and graphics

    R is "a language and environment for statistical computing and graphics": a programming language with methods for tests, models and plots ready to use.

  2. Question 2 of 15 A colleague installs RStudio on a new laptop, opens it and is told that no R installation was found. What is missing?

    Choose one answer.

    Show the answer: Question 2 of 15

    Answer: R itself, because RStudio is an editor that runs R

    Install R first, then the editor. The next lesson does exactly that, on Windows, macOS and Linux.

  3. Question 3 of 15 Twenty patients had their blood pressure measured before and after a new drug, stored in the same patient order as before and after. Which call tests whether it changed?

    Choose one answer.

    Show the answer: Question 3 of 15

    Answer: t.test(after, before, paired = TRUE)

    Two measurements of the same people call for a paired test, as the volunteers' two nights did. The output then reports the mean difference with its confidence interval and p-value.

  4. Question 4 of 15 How many base packages does R 4.6.1 have, as tools::standard_package_names() lists them?

    Type a number.

    Show the answer: Question 4 of 15

    Answer: 14 packages

    The run printed base 14 and recommended 15: base, tools, utils, grDevices, graphics, stats, datasets, methods, grid, splines, stats4, tcltk, compiler and parallel.

  5. Question 5 of 15 Which of these is one of R's recommended packages?
    Show the answer: Question 5 of 15

    Answer: survival

    The recommended packages are MASS, lattice, Matrix, nlme, survival, boot, cluster, codetools, foreign, KernSmooth, rpart, class, nnet, spatial and mgcv.

  6. Question 6 of 15 You installed a CRAN package yesterday. Today, in a new session, its functions are "not found". What do you run?

    Choose one answer.

    Show the answer: Question 6 of 15

    Answer: library() with the package's name

    Install once with install.packages(), then attach in every session with library(). The next lesson shows both and the error you see when a package is missing.

  7. Question 7 of 15 A colleague has a fresh R from CRAN's installer. Your script starts with library(stats), library(survival) and library(lme4). What must they install first?

    Choose one answer.

    Show the answer: Question 7 of 15

    Answer: Only lme4

    Base packages are part of R, recommended packages come with R's installers, and every contributed package is installed by the user, once, with install.packages().

  8. Question 8 of 15 In the comparison, what is SQL in a database the best tool for?

    Choose one answer.

    Show the answer: Question 8 of 15

    Answer: Filtering, joining and summing large tables where they live

    Each tool has its step: SQL to cut large tables down, R to model and plot the result, Python for analysis inside other software, a spreadsheet for a quick look by hand.

  9. Question 9 of 15 A monthly report is made by pasting data into a spreadsheet and clicking through the same twelve steps. What is the main risk?

    Choose one answer.

    Show the answer: Question 9 of 15

    Answer: The steps leave no record, so a rerun can differ without anyone noticing

    Once steps must run again on new data, write them as a script: every run then does the same thing, and the script records what was done.

  10. Question 10 of 15 A study needs a survival analysis of 5 million hospital records stored in a database, of which it uses 40,000. Which plan fits best?

    Choose one answer.

    Show the answer: Question 10 of 15

    Answer: Select and summarise the 40,000 records with SQL, then fit the survival model in R

    Many projects use two tools: SQL to select and summarise, R to model. The survival model needs only the 40,000 records the study uses.

  11. Question 11 of 15 In R 4.6.1, which number is the patch level?

    Choose one answer.

    Show the answer: Question 11 of 15

    Answer: 1

    Major, minor, patch: 4.6.1 is the first patch release of R 4.6. R has one x.y.0 release a year and patch releases in between when they are needed.

  12. Question 12 of 15 A script uses the native pipe |>. What is the oldest R it can run on?

    Choose one answer.

    Show the answer: Question 12 of 15

    Answer: R 4.1.0

    The timeline shows when each feature arrived. A script states the oldest R it needs, so a reader with an older R knows why it fails.

  13. Question 13 of 15 Which line makes a script stop with a clear message on an R older than 4.1.0, and run on every later version?

    Choose one answer.

    Show the answer: Question 13 of 15

    Answer: stopifnot(getRversion() >= "4.1.0")

    Compare versions as versions: getRversion() against a version written as text, which R converts to a version before comparing.

  14. Question 14 of 15 What does citation() with no argument print?

    Choose one answer.

    Show the answer: Question 14 of 15

    Answer: The reference for R itself and a BibTeX entry for it

    citation() prints the R Core Team's reference for R, with the DOI 10.32614/R.manuals, and the same as a BibTeX entry.

  15. Question 15 of 15 What does citation("stats") print?

    Choose one answer.

    Show the answer: Question 15 of 15

    Answer: That stats is part of R, followed by the reference for R

    For a base package, cite R. For a contributed or recommended package, cite the package's own reference as well, with its version.

Interview questions

Warm-up: what is the difference between a base package, a recommended package and a contributed package?

A base package is part of R itself: the 14 of them, such as base, stats, utils and graphics, come with every R and carry R’s own version number, so they change only with a new R release. A recommended package is one of 15, such as MASS, Matrix, survival and mgcv, that R’s binary distributions install alongside the base packages; they are also published on CRAN, where they get updates between R releases. A contributed package is everything else: one of more than 25,000 packages on CRAN, or a Bioconductor package, which you install yourself with install.packages() or BiocManager::install(). In practice the difference decides what a colleague with a fresh R must install before your script runs: nothing for stats, nothing for survival if their R came from an official installer, and every contributed package your script loads.

Model answers open with any pass: ₹79 for 1 week ($2.99), one payment that never renews.

  1. Fresher to mid

    Your analysis script runs on your laptop. On a colleague's computer library(lme4) fails, and once that is fixed, the same model gives slightly different estimates. What do you compare between the two setups, and what do you report in a paper so that others can repeat the result?

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page. First step and follow-ups

  2. Mid to senior

    A research group analyses its survey data in spreadsheets, and each monthly report takes two days of copying and clicking. Make the case for or against moving the analysis to R, and say how you would switch without interrupting the monthly reports.

    Model answer, Pro. First step and follow-ups

Key takeaways

  • R is “a language and environment for statistical computing and graphics”: a paired t-test of eight volunteers is one call, and it prints the test statistic, the p-value and a confidence interval.
  • Fourteen base packages are part of R and fifteen recommended ones come with every installer; the rest come from CRAN, with more than 25,000 packages, or from Bioconductor, whose release 3.23, made for R 4.6, has 2,418 software packages for biology.
  • R fits models, tests and research graphics; SQL suits large tables in a database, Python suits analysis inside other software, and a spreadsheet suits a quick look by hand.
  • R 4.6.1 is major version 4, minor version 6, patch level 1; there is one x.y.0 release a year, and versions are compared with getRversion(), never as text.
  • citation() prints the reference for R with its DOI, 10.32614/R.manuals, and citation("name") the reference for a package.

Terms in this lesson

base package
One of the 14 packages that are part of R itself, such as base, stats, utils and graphics. They carry R's own version number.
Bioconductor
An archive of R packages for genomics and biology, with one release for each R version. Its packages are installed with BiocManager::install().
CRAN
The Comprehensive R Archive Network: a set of mirrored sites that carry R itself and the contributed packages that install.packages() installs.
package
A bundle of R functions, data and help pages. It is installed once into a package library and attached to a session with library().
recommended package
One of the 15 packages, such as MASS, Matrix, survival and mgcv, that every binary distribution of R installs alongside the base packages.
task view
A CRAN page that lists and describes the packages for one topic, such as Bayesian statistics, econometrics or survival analysis.

References

Related tools

Report a problem with this lesson

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.