
14 R code
14.1 File formats
As per the study definition best practice, outputs from the cohortextractor should be provided as
.rdsfilesUse the readr package to read and write
.rdsfilesobject <- readr::read_rds(file.path("output", "mydata.rds")) readr::write_rds(object, file.path("output", "mydata.rds"), compress = "gz")
- All
.rdsfiles should all be classified ashighly_sensitivein actions, as they cannot be opened on the results server and therefore cannot be reviewed or released. readr::write_rds()does not compress files by default. It is recommended that you compress .rds files using the argumentcompress = "gz".- Use
file.path()to construct file paths that are reproducible across operating systems.
14.2 Supported packages
14.3 RStudio project
- Define your repo as an RStudio project in RStudio as follows
File | New Project…
Existing Directory

Then find your repo
This will create a
.Rprojfile at the top level of your repoCommit the file into your repo
Now you can double click the
.Rprojfile to open the repo in RStudio, so you can work on your R scripts more conveniently