14 R code
14.1 File formats
As per the study definition best practice, outputs from the cohortextractor should be provided as
.rds
filesUse the readr package to read and write
.rds
files<- readr::read_rds(file.path("output", "mydata.rds")) object ::write_rds(object, readrfile.path("output", "mydata.rds"), compress = "gz")
- All
.rds
files should all be classified ashighly_sensitive
in 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
.Rproj
file at the top level of your repoCommit the file into your repo
Now you can double click the
.Rproj
file to open the repo in RStudio, so you can work on your R scripts more conveniently