library(REDCapR)
# Returns the variables "record_id" and "age".
<- redcap_read(
ds_some_vars redcap_uri = keyring::key_get("DB_URI"), # This is the address for projects at the AU-server
token = keyring::key_get("API_KEY"),
fields = c("record_id", "age")
$data
)
# Return only records with IDs of 1 and 4
<- redcap_read(
ds_some_rows redcap_uri = keyring::key_get("DB_URI"), # This is the address for projects at the AU-server
token = keyring::key_get("API_KEY"),
records = c(1, 4)
$data )
2 Downloading data
Please make sure to read the previous chapter on how to getting access to the database.
Using the REDCap API to access and download data from a database, there are two different approaches:
- A focused, “get what you need”-approach and
- a more simple “get it all”-approach
Working with longitudinal projects and/or repeated instruments will result in castellated dataset. The package library(REDCapTidieR)
(Hanna, Kadauke, and Porter 2023) provides a solution to the castellation, but downloads full instruments, which is not always desirable.
In the following, the two approaches will be demonstrated including a possible third approach, requiring a little more technical willingness.
2.0.1 Focus
There are different packages to access and download data from R. In the , available tools and packages are referenced. Here I will provide an example, as to download minimal data in a focused way, using REDCapR.(Beasley 2022).
Please have a look in the REDCap-chapter for an optimised approach when handling events and repeated instruments.
To get a full list of available variable names, you can either go through the codebook on REDCap, or you can try the following, but be aware, that the resulting vector of variable names can get a little long and confusing.
# Returns a vector of names of all accessible variables.
<- redcap_read(
variable_names redcap_uri = keyring::key_get("DB_URI"), # This is the address for projects at the AU-server
token = keyring::key_get("API_KEY")
$data |>
)colnames()
Here is an example on how to export data on RBANS and cleaning the data for plotting.
<- redcap_read(
ds redcap_uri = keyring::key_get("DB_URI"), # This is the address for projects at the AU-server
token = keyring::key_get("API_KEY"),
records = c(1:35), # Downloading data from ID 1 to 35.
forms = "rbans", # Downloading only the RBANS instrument
event = c("3_months_arm_1", # Specifying only to download 3 and 12 months data
"12_months_arm_1")
$data |>
)select( # Selecting variables to keep
c("record_id",
"redcap_event_name",
ends_with(c("_is","_lo","_up","_per"))) # I only want index scores, lower and upper CIs and percentile.
|>
) na.omit() # Omitting IDs with missing data.
head(ds, n = 5) # Showing only the first 5 rows
Further examples and scripts can be found in the ENIGMA code repository.