Software first contact

RStudio: first contact

New to RStudio? Find the project, script, data and output, then run one checked block with the shared cohort.

Use this optional on-ramp when the statistics desk is new. You will open the common cohort, run one saved block and be ready for Jennifer’s Analysis Step 01.

Your short software on-ramp

Learn just enough software to begin Jennifer’s analysis.

This is not a separate statistics course. It teaches only the software moves needed to open the shared cohort, run a saved instruction and recognise a correct result.

Before you start: no software knowledge is required. This page prepares the statistics desk; it does not teach the whole analysis. You need access to RStudio and permission to save the teaching files in one folder. Read Jennifer’s fictional study background before beginning Step 01.

By the end you can

  • identify where data, saved instructions and output live;
  • open the 720-row teaching cohort without changing the source file;
  • run one reproducible frequency and age summary;
  • recognise the expected result and fix common first-run errors.

1 · Purpose

What RStudio is for.

R is the statistical language; RStudio is the desktop or browser environment used to write, run and organise R. In medical research, this pairing supports transparent data checking, epidemiological tables, regression, survival analysis, graphics and reproducible reporting.

The safe mental model is data + script → objects + output. The Environment pane is temporary. A fresh R session should be able to recreate every object from the saved script and unchanged data.

Data

One patient-shaped table

Rows are participants; columns are variables. A blank follow-up value is missing, not “no event”.

Instructions

One saved record

Menus can help you discover a procedure, but the commands or script make the work inspectable and repeatable.

Output

Evidence to interpret

Tables, estimates, intervals, warnings and plots are results, not a substitute for the saved analysis instructions.

2 · Open or access it

Start with the supported route.

R is free. RStudio Desktop is also available without charge; some universities provide RStudio through Posit Workbench in a browser. Use the institutionally supported route if one is available.

  1. Desktop: install R from CRAN first, then install RStudio Desktop from Posit.
  2. Institutional browser: sign in to the university’s Posit Workbench/RStudio Server and create or upload one project folder.
  3. Open the supplied .Rproj. Its name should appear at the top right before you run the script.

R and RStudio are different programs. If RStudio says it cannot find R, install or select the R engine before troubleshooting the analysis.

3 · Find the statistics desk

Know where each part of the work lives.

Source

Write and save .R scripts. Run the current line or selection with Ctrl+Enter, or Cmd+Enter on macOS.

Console

Shows commands as they execute and prints results, warnings and errors. It is temporary, not the analysis record.

Environment

Lists objects currently in memory. Useful for orientation; the script should be able to recreate all of them.

Output

Files, plots, packages, help and the Viewer appear in tabs here.

RStudio interface labelled with Source, Console, Environment and Output panes
Work moves clockwise: write code in Source, watch it run in the Console, inspect created objects in Environment and review files, plots and help in Output. The script, not the Environment pane, must be able to recreate the analysis.

4 · First reproducible run

Open the shared cohort and ask two simple questions.

Put the .Rproj, supplied .R script and CSV in one folder. Open the project, then open the script in Source. Run the block below with Ctrl+Enter on Windows/Linux or Cmd+Enter on macOS.

The code creates an object named cohort, checks its shape, and answers the same two questions as the Stata and SPSS on-ramps: medication-review frequency and the cohort’s age summary.

cohort <- read.csv(
  "gerostats_medication_review_cohort.csv",
  na.strings = c("", "NA")
)

dim(cohort)
table(cohort$med_review, useNA = "ifany")
round(prop.table(table(cohort$med_review)) * 100, 1)
c(
  mean = mean(cohort$age_years),
  min = min(cohort$age_years),
  max = max(cohort$age_years)
)

Complete R script

Use its opening block now; later sections match the guided medical-statistics journey.

Download the .R file

5 · Successful output

Check the result before moving on.

Expected result

[1] 720  16

  0   1
517 203

   0    1
71.8 28.2

    mean      min      max
78.34722 65.00000 96.00000

Values 0 and 1 are codes, not yet reader-friendly labels. Step 01 keeps the raw field auditable and adds labels for interpretation. These summaries describe the cohort; they do not test an effect of medication review.

6 · First-run problems

Read the message; fix the cause.

cannot open file

The CSV is not in the project folder or its filename differs. Confirm the project name at top right and inspect the Files pane.

object 'cohort' not found

The import line did not run successfully. Run from the first line downward; later commands depend on the object it creates.

unexpected symbol

Check quotation marks, commas and closing parentheses. Run the supplied block unchanged before editing it.

The dimensions are not 720 × 16

Stop. Re-download the shared CSV and make sure R read the comma-delimited file with the header row.

Terms you now need

Data frame
a rectangular R object with observations in rows and variables in columns.
Object
a named item in memory, such as the imported data frame cohort.
Script
the saved .R file that recreates the analysis.
Console
where R executes code and prints values, warnings and errors.
Go deeper · medical-statistics and official RStudio resources

Optional references for software detail, epidemiological methods and reproducible health-research reporting. You do not need these to begin Step 01.

Workflow · official Posit

RStudio Projects and blank-slate work

Keep health-study data, scripts and outputs together and recreate analysis from source.

Open the RStudio guide
Language · official R

An Introduction to R

Objects, data frames, factors, tables, models and graphics in the official R manual.

Read the R manual
Epidemiology · CRAN

Epi package reference

Functions and documentation for applied epidemiological data analysis, rates and follow-up data.

Open the Epi package page
Medical statistics · BMJ

Statistics at Square One

Clinical examples covering displays, uncertainty, tests and study design; the free online text is an older edition.

Open the BMJ reference

On-ramp complete

Now meet the cohort properly.

You can open the shared data, run saved instructions and recognise a correct first result. Continue to Jennifer’s Analysis Step 01, where you will check the study design, timeline, variables and whether the file matches the fictional study.

Jennifer’s cohort · Analysis Step 01 Meet the cohort →