-
Notifications
You must be signed in to change notification settings - Fork 1
/
getREDCap.R
28 lines (22 loc) · 1.04 KB
/
getREDCap.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
## Examples of reading in data from REDCap
## Need to install REDCapR from github, which will allow survey timestamp
## to be download:
## install.packages("devtools") # Run this line if the 'devtools' package isn't installed already.
## devtools::install_github(repo="OuhscBbmc/REDCapR")
## Use keyring to manage API security
library(data.table)
library(REDCapR)
library(keyring)
## Create API in macOS keychain
## key_set("ProjectName", "Username")
## Enter API as password when prompted
redcap_api <- key_get("ProjectName")
## Uncomment below to retrieve specific records or varibles
## return_records <- c(1, 4)
## return_fields <- c("id", "name", "age")
d <- as.data.table(redcap_read(redcap_uri = "https://redcap.cdms.org.au/api/",
token = redcap_api,
export_survey_fields = TRUE # needed to be TRUE for timestamp to be retrieved
## fields = return_fields,
## records = return_records
)$data)