vignettes/BasicREDCapROperations.Rmd
BasicREDCapROperations.Rmd
If no information is passed about the desired records or fields, then the entire data set is returned. Only two parameters are required, redcap_uri
and token
. Unless the verbose
parameter is set to FALSE
, a message will be printed on the R console with the number of records and fields returned.
#Return all records and all variables.
ds_all_rows_all_fields <- redcap_read(redcap_uri=uri, token=token)$data
The data dictionary describing 16 fields was read from REDCap in 0.7 seconds. The http status code was 200.
-5 records and 1 columns were read from REDCap in 0.4 seconds. The http status code was 200.
-Starting to read 5 records at 2019-09-20 18:16:13.
+The data dictionary describing 16 fields was read from REDCap in 0.5 seconds. The http status code was 200.
+5 records and 1 columns were read from REDCap in 0.3 seconds. The http status code was 200.
+Starting to read 5 records at 2019-09-22 15:36:56.
Reading batch 1 of 1, with subjects 1 through 5 (ie, 5 unique subject records).
-5 records and 24 columns were read from REDCap in 1.4 seconds. The http status code was 200.
+5 records and 24 columns were read from REDCap in 0.3 seconds. The http status code was 200.
record_id name_first name_last address
1 1 Nutmeg Nutmouse 14 Rose Cottage St.\nKenning UK, 323232
@@ -192,11 +192,11 @@
token = token,
records = desired_records_v1
)$data
The data dictionary describing 16 fields was read from REDCap in 0.5 seconds. The http status code was 200.
-2 records and 1 columns were read from REDCap in 0.4 seconds. The http status code was 200.
-Starting to read 2 records at 2019-09-20 18:16:16.
+The data dictionary describing 16 fields was read from REDCap in 0.2 seconds. The http status code was 200.
+2 records and 1 columns were read from REDCap in 0.3 seconds. The http status code was 200.
+Starting to read 2 records at 2019-09-22 15:36:58.
Reading batch 1 of 1, with subjects 1 through 3 (ie, 2 unique subject records).
-2 records and 24 columns were read from REDCap in 1 seconds. The http status code was 200.
+2 records and 24 columns were read from REDCap in 0.3 seconds. The http status code was 200.
#Return only records with IDs of 1 and 3 (alternate way)
desired_records_v2 <- "1, 3"
ds_some_rows_v2 <- redcap_read(
@@ -205,10 +205,10 @@
records_collapsed = desired_records_v2
)$data
The data dictionary describing 16 fields was read from REDCap in 0.3 seconds. The http status code was 200.
-2 records and 1 columns were read from REDCap in 0.3 seconds. The http status code was 200.
-Starting to read 2 records at 2019-09-20 18:16:18.
+2 records and 1 columns were read from REDCap in 0.2 seconds. The http status code was 200.
+Starting to read 2 records at 2019-09-22 15:36:59.
Reading batch 1 of 1, with subjects 1 through 3 (ie, 2 unique subject records).
-2 records and 24 columns were read from REDCap in 0.5 seconds. The http status code was 200.
+2 records and 24 columns were read from REDCap in 0.4 seconds. The http status code was 200.
record_id name_first name_last address
1 1 Nutmeg Nutmouse 14 Rose Cottage St.\nKenning UK, 323232
@@ -237,11 +237,11 @@
token = token,
fields = desired_fields_v1
)$data
-The data dictionary describing 16 fields was read from REDCap in 1.2 seconds. The http status code was 200.
-5 records and 1 columns were read from REDCap in 1.1 seconds. The http status code was 200.
-Starting to read 5 records at 2019-09-20 18:16:21.
+The data dictionary describing 16 fields was read from REDCap in 0.2 seconds. The http status code was 200.
+5 records and 1 columns were read from REDCap in 0.3 seconds. The http status code was 200.
+Starting to read 5 records at 2019-09-22 15:37:01.
Reading batch 1 of 1, with subjects 1 through 5 (ie, 5 unique subject records).
-5 records and 3 columns were read from REDCap in 1.1 seconds. The http status code was 200.
+5 records and 3 columns were read from REDCap in 0.4 seconds. The http status code was 200.
#Return only the fields record_id, name_first, and age (alternate way)
desired_fields_v2 <- "record_id, name_first, age"
ds_some_fields_v2 <- redcap_read(
@@ -249,11 +249,11 @@
token = token,
fields_collapsed = desired_fields_v2
)$data
The data dictionary describing 16 fields was read from REDCap in 0.6 seconds. The http status code was 200.
-5 records and 1 columns were read from REDCap in 0.9 seconds. The http status code was 200.
-Starting to read 5 records at 2019-09-20 18:16:24.
+The data dictionary describing 16 fields was read from REDCap in 0.5 seconds. The http status code was 200.
+5 records and 1 columns were read from REDCap in 0.2 seconds. The http status code was 200.
+Starting to read 5 records at 2019-09-22 15:37:02.
Reading batch 1 of 1, with subjects 1 through 5 (ie, 5 unique subject records).
-5 records and 3 columns were read from REDCap in 1.9 seconds. The http status code was 200.
+5 records and 3 columns were read from REDCap in 0.3 seconds. The http status code was 200.
record_id name_first age
1 1 Nutmeg 11
@@ -274,11 +274,11 @@
token = token,
fields = desired_fields_v3
)$data
-The data dictionary describing 16 fields was read from REDCap in 0.3 seconds. The http status code was 200.
-5 records and 1 columns were read from REDCap in 0.5 seconds. The http status code was 200.
-Starting to read 5 records at 2019-09-20 18:16:28.
+The data dictionary describing 16 fields was read from REDCap in 0.2 seconds. The http status code was 200.
+5 records and 1 columns were read from REDCap in 0.3 seconds. The http status code was 200.
+Starting to read 5 records at 2019-09-22 15:37:04.
Reading batch 1 of 1, with subjects 1 through 5 (ie, 5 unique subject records).
-5 records and 3 columns were read from REDCap in 0.5 seconds. The http status code was 200.
+5 records and 3 columns were read from REDCap in 0.3 seconds. The http status code was 200.
record_id dob weight
1 1 2003-08-30 1
@@ -303,10 +303,10 @@
records = desired_records_v3
)$data
The data dictionary describing 16 fields was read from REDCap in 0.3 seconds. The http status code was 200.
-2 records and 1 columns were read from REDCap in 0.6 seconds. The http status code was 200.
-Starting to read 2 records at 2019-09-20 18:16:29.
+2 records and 1 columns were read from REDCap in 0.3 seconds. The http status code was 200.
+Starting to read 2 records at 2019-09-22 15:37:05.
Reading batch 1 of 1, with subjects 3 through 5 (ie, 2 unique subject records).
-2 records and 24 columns were read from REDCap in 0.8 seconds. The http status code was 200.
+2 records and 24 columns were read from REDCap in 0.3 seconds. The http status code was 200.
record_id name_first name_last address
1 3 Marcus Wood 243 Hill St.\nGuthrie OK 73402
@@ -346,11 +346,11 @@
token = token,
fields = desired_fields_v1
)
-The data dictionary describing 16 fields was read from REDCap in 0.8 seconds. The http status code was 200.
-5 records and 1 columns were read from REDCap in 0.5 seconds. The http status code was 200.
-Starting to read 5 records at 2019-09-20 18:16:32.
+The data dictionary describing 16 fields was read from REDCap in 0.3 seconds. The http status code was 200.
+5 records and 1 columns were read from REDCap in 0.2 seconds. The http status code was 200.
+Starting to read 5 records at 2019-09-22 15:37:07.
Reading batch 1 of 1, with subjects 1 through 5 (ie, 5 unique subject records).
-5 records and 3 columns were read from REDCap in 1 seconds. The http status code was 200.
+5 records and 3 columns were read from REDCap in 0.3 seconds. The http status code was 200.
$data
record_id name_first age
@@ -367,7 +367,7 @@
[1] "200"
$outcome_messages
-[1] "5 records and 3 columns were read from REDCap in 1 seconds. The http status code was 200."
+[1] "5 records and 3 columns were read from REDCap in 0.3 seconds. The http status code was 200."
$records_collapsed
[1] ""
@@ -385,7 +385,7 @@
[1] ""
$elapsed_seconds
-[1] 2.970515
+[1] 1.336262
Report rendered by wibeasley at 2019-09-20, 18:16 -0600 in 28 seconds.
+Report rendered by wibeasley at 2019-09-22, 15:37 -0500 in 15 seconds.
vignettes/SecurityDatabase.Rmd
SecurityDatabase.Rmd
vignettes/TroubleshootingApiCalls.Rmd
TroubleshootingApiCalls.Rmd
Can an administrator query the API successfully with Postman with the admin token? As an administrator, create an account for yourself, and verify that your token works on your server and project.
Can an administrator query the API successfully with Postman with the user’s token? Use Postman as before, but replace your token with the user’s token. Once the whole problem is solved, reissue new API tokens to both you and the user.
Can an user query the API successfully with Postman with the their own token? The values they enter should be exactly the same as those entered in the previous step. A failure here (assuming the previous step was successful) suggests a network or firewall issue. If the server is behind your institution’s firewall, verify the user is connecting successfully through the VPN.
Can a user query the API with cURL? cURL is a command line tool that’s underneath a lot of libraries. If it’s installed correctly on your location machine, it can be executed from the terminal or command line. shell curl -X POST -H "Cache-Control: no-cache" -F "token=9A81268476645C4E5F03428B8AC3AA7B" -F "content=record" -F "format=csv" "https://bbmc.ouhsc.edu/redcap/api/"
Can a user query the API with cURL? cURL is a command line tool that’s underneath a lot of libraries. If it’s installed correctly on your location machine, it can be executed from the terminal or command line.
+curl -X POST -H "Cache-Control: no-cache" -F "token=9A81268476645C4E5F03428B8AC3AA7B" -F "content=record" -F "format=csv" "https://bbmc.ouhsc.edu/redcap/api/"
+Is httr installed on the user’s local machine? If so, running library(httr)
should not produce any error messages if you’re starting with a fresh session of R:
Does the user have the most recent version of httr? There are several ways to do this, but the easiest is probably to run update.packages(ask=FALSE, repos="http://cran.rstudio.com")
. The optional argument ask
prevents the user from needing to respond ‘Y’ to each outdated package.
Can the user query a test project using httr? Both the redcapAPI and REDCapR packages employ something similar to the following function in httr. If you’re curious, here is the relevant source code for redcapAPI and REDCapR.
If this check fails, consider attempting again with the uri and token used above in the Postman example.
This check avoids checking the SSL certificate in order to simplify the troubleshooting. SSL verification is supported by default in the PyCap, redcapAPI, and REDCapR packages.
-redcap_uri <- "https://bbmc.ouhsc.edu/redcap/api/"
-token <- "9A81268476645C4E5F03428B8AC3AA7B"
-
-raw_text <- RCurl::postForm(
- uri = redcap_uri
- , token = token
- , content = 'record'
- , format = 'csv'
- , type = 'flat'
- , rawOrLabel = 'raw'
- , exportDataAccessGroups = 'true'
- , .opts = RCurl::curlOptions(ssl.verifypeer=FALSE)
-)
redcap_uri <- "https://bbmc.ouhsc.edu/redcap/api/"
+token <- "9A81268476645C4E5F03428B8AC3AA7B"
+
+raw_text <- RCurl::postForm(
+ uri = redcap_uri
+ , token = token
+ , content = 'record'
+ , format = 'csv'
+ , type = 'flat'
+ , rawOrLabel = 'raw'
+ , exportDataAccessGroups = 'true'
+ , .opts = RCurl::curlOptions(ssl.verifypeer=FALSE)
+)
Alternatively, you can try using the httr
package, which uses RCurl
underneath. REDCapR
and a recent fork of redcap
actually uses httr
directly, instead of RCurl
. As of 2014-07-06, this works with the Windows 8 version for libcurl (which is underneath `RCurl), but not with some Linux versions; in this case pass the location of the SSL cert file.
post_body <- list(
- token = token,
- content = 'record',
- format = 'csv',
- type = 'flat',
- rawOrLabel = 'raw',
- exportDataAccessGroups = 'true'
-)
-
-raw_text <- httr::POST(
- url = redcap_uri,
- body = post_body,
- config = httr::config(ssl.verifypeer=FALSE),
- httr::verbose() #Remove this line to suppress the frequent console updates.
-)
post_body <- list(
+ token = token,
+ content = 'record',
+ format = 'csv',
+ type = 'flat',
+ rawOrLabel = 'raw',
+ exportDataAccessGroups = 'true'
+)
+
+raw_text <- httr::POST(
+ url = redcap_uri,
+ body = post_body,
+ config = httr::config(ssl.verifypeer=FALSE),
+ httr::verbose() #Remove this line to suppress the frequent console updates.
+)
Can the user query a subset of their project using RCurl? This step is like the previous one, but with two differences. First, it’s using their REDCap project (instead of the test project). Second, it pulls fewer records, and a smaller collection of fields. Subsetting can help troubleshoot by avoiding (and thus identifying) cells with problematic values.
Notice this call to RCurl::postForm()
now passes values to the records
and fields
parameters. Also notice the value is a single long string, rather a vector of shorter strings (which is more natural to most R users).
redcap_uri <- "https://the.urlofyourinsitution.edu/api/"
-token <- "your-secret-token"
-records_collapsed <- "1,2,3" # Assumes dataset contains ID values of 1-3.
-fields_collapsed <- "record_id,name_first,name_last" # Assumes dataset contains these variables.
-
-raw_text <- RCurl::postForm(
- uri = redcap_uri
- , token = token
- , content = 'record'
- , format = 'csv'
- , type = 'flat'
- , rawOrLabel = 'raw'
- , exportDataAccessGroups = 'true'
- , records = records_collapsed
- , fields = fields_collapsed
- , .opts = RCurl::curlOptions(ssl.verifypeer=FALSE)
-)
redcap_uri <- "https://the.urlofyourinsitution.edu/api/"
+token <- "your-secret-token"
+records_collapsed <- "1,2,3" # Assumes dataset contains ID values of 1-3.
+fields_collapsed <- "record_id,name_first,name_last" # Assumes dataset contains these variables.
+
+raw_text <- RCurl::postForm(
+ uri = redcap_uri
+ , token = token
+ , content = 'record'
+ , format = 'csv'
+ , type = 'flat'
+ , rawOrLabel = 'raw'
+ , exportDataAccessGroups = 'true'
+ , records = records_collapsed
+ , fields = fields_collapsed
+ , .opts = RCurl::curlOptions(ssl.verifypeer=FALSE)
+)
Can the user query an entire project using RCurl? There are two advantages of trying a subset of the data. First, small datasets avoid the time-out errors that plague large datasets. Second, it may avoid problematic values being passed through the pipeline. If the current check fails but the previous check succeeds, then experiment with different expanses of records and fields. This should help determine which values are causing the problems, or if there’s simply too much data being pulled in one pass.
If the desired dataset is too large, consider if you can prune unnecessary records or fields. If not, one solution is to pull smaller, multiple batches using the API, then reassemble them. The redcap_read()
function in REDCapR does this automatically, and allows the user to specify a batch_size
.
redcap_uri <- "https://the.urlofyourinsitution.edu/api/"
-token <- "your-secret-token"
-records_collapsed <- NULL
-fields_collapsed <- NULL
-
-raw_text <- RCurl::postForm(
- uri = redcap_uri
- , token = token
- , content = 'record'
- , format = 'csv'
- , type = 'flat'
- , rawOrLabel = 'raw'
- , exportDataAccessGroups = 'true'
- , records = records_collapsed
- , fields = fields_collapsed
- , .opts = RCurl::curlOptions(ssl.verifypeer=FALSE)
-)
redcap_uri <- "https://the.urlofyourinsitution.edu/api/"
+token <- "your-secret-token"
+records_collapsed <- NULL
+fields_collapsed <- NULL
+
+raw_text <- RCurl::postForm(
+ uri = redcap_uri
+ , token = token
+ , content = 'record'
+ , format = 'csv'
+ , type = 'flat'
+ , rawOrLabel = 'raw'
+ , exportDataAccessGroups = 'true'
+ , records = records_collapsed
+ , fields = fields_collapsed
+ , .opts = RCurl::curlOptions(ssl.verifypeer=FALSE)
+)
REDCapR is a package that uses cURL (via httr) to communicate with REDCap, and wraps convenience functions around it to reduce the size and complexity of the user’s code. The package’s basic functions are demonstrated in a vignette and are documented in its reference manual (a downloadable pdf of the functions are also available).
If you’re not using REDCapR, you can skip this section and proceed to ‘Importing into REDCap from R’ below.
Is REDCapR installed on the user’s machine? Currently the easiest way to install REDCapR is with the devtools. The follow code installs devtools, then installs REDCapR. r install.packages("devtools", repos="http://cran.rstudio.com") devtools::install_github(repo="OuhscBbmc/REDCapR")
Does REDCapR load successfully on the user’s machine? If so, running library(REDCapR)
should produce the following output if you’re starting with a fresh session of R: r library(REDCapR) ## Loading required package: REDCapR
Can the user export from an example project? This is the same fake data hosted by the OUHSC BBMC as in the previous section. r library(REDCapR) #Load the package into the current R session. uri <- "https://bbmc.ouhsc.edu/redcap/api/" token <- "9A81268476645C4E5F03428B8AC3AA7B" redcap_read(redcap_uri=uri, token=token)$data
The previous code should produce similar output. Notice there are five rows and the columns will wrap around if your console window is too narrow. ``` 5 records and 1 columns were read from REDCap in 0.41 seconds. Starting to read 5 records at 2014-06-27 17:19:49 Reading batch 1 of 1, with ids 1 through 5. 5 records and 16 columns were read from REDCap in 0.42 seconds.
-record_id name_first name_last address telephone email 1 1 Nutmeg Nutmouse 14 Rose Cottage St.UK, 323232 (432) 456-4848 nutty@mouse.com 2 2 Tumtum Nutmouse 14 Rose Cottage Blvd.UK 34243 (234) 234-2343 tummy@mouse.comm 3 3 Marcus Wood 243 Hill St.OK 73402 (433) 435-9865 mw@mwood.net 4 4 Trudy DAG 342 ElmTX, 75116 (987) 654-3210 peroxide@blonde.com 5 5 John Lee Walker Hotel SuiteOrleans LA, 70115 (333) 333-4444 left@hippocket.com
- dob age ethnicity race sex height weight bmi
-1 2003-08-30 10 1 2 0 5.00 1 400.0 2 2003-03-10 10 1 6 1 6.00 1 277.8 3 1934-04-09 79 0 4 1 180.00 80 24.7 4 1952-11-02 61 1 4 0 165.00 54 19.8 5 1955-04-15 58 1 4 1 193.04 104 27.9
- comments
-1 Character in a book, with some guessing 2 A mouse character from a good book 3 completely made up 4 This record doesn’t have a DAG assignedcall up Trudy on the telephoneher a letter in the mail 5 Had a hand for trouble and a eye for cashhad a gold watch chain and a black mustache
-demographics_complete 1 2 2 2 3 2 4 2 5 2 ```
+Is REDCapR installed on the user’s machine? Currently the easiest way to install REDCapR is with the devtools. The follow code installs devtools, then installs REDCapR.
+ +Does REDCapR load successfully on the user’s machine? If so, running library(REDCapR)
should produce the following output if you’re starting with a fresh session of R:
Can the user export from an example project? This is the same fake data hosted by the OUHSC BBMC as in the previous section.
+library(REDCapR) #Load the package into the current R session.
+uri <- "https://bbmc.ouhsc.edu/redcap/api/"
+token <- "9A81268476645C4E5F03428B8AC3AA7B"
+redcap_read(redcap_uri=uri, token=token)$data
The previous code should produce similar output. Notice there are five rows and the columns will wrap around if your console window is too narrow.
+5 records and 1 columns were read from REDCap in 0.41 seconds.
+Starting to read 5 records at 2014-06-27 17:19:49
+Reading batch 1 of 1, with ids 1 through 5.
+5 records and 16 columns were read from REDCap in 0.42 seconds.
+
+ record_id name_first name_last address telephone email
+1 1 Nutmeg Nutmouse 14 Rose Cottage St.\nKenning UK, 323232 (432) 456-4848 nutty@mouse.com
+2 2 Tumtum Nutmouse 14 Rose Cottage Blvd.\nKenning UK 34243 (234) 234-2343 tummy@mouse.comm
+3 3 Marcus Wood 243 Hill St.\nGuthrie OK 73402 (433) 435-9865 mw@mwood.net
+4 4 Trudy DAG 342 Elm\nDuncanville TX, 75116 (987) 654-3210 peroxide@blonde.com
+5 5 John Lee Walker Hotel Suite\nNew Orleans LA, 70115 (333) 333-4444 left@hippocket.com
+
+ dob age ethnicity race sex height weight bmi
+1 2003-08-30 10 1 2 0 5.00 1 400.0
+2 2003-03-10 10 1 6 1 6.00 1 277.8
+3 1934-04-09 79 0 4 1 180.00 80 24.7
+4 1952-11-02 61 1 4 0 165.00 54 19.8
+5 1955-04-15 58 1 4 1 193.04 104 27.9
+
+ comments
+1 Character in a book, with some guessing
+2 A mouse character from a good book
+3 completely made up
+4 This record doesn't have a DAG assigned\n\nSo call up Trudy on the telephone\nSend her a letter in the mail
+5 Had a hand for trouble and a eye for cash\n\nHe had a gold watch chain and a black mustache
+
+ demographics_complete
+1 2
+2 2
+3 2
+4 2
+5 2
Can the user export from their own project? The code is similar to the previous check, but the uri
and token
values will need to be modified. r library(REDCapR) #Load the package into the current R session, if you haven't already. redcap_uri <- "https://the.urlofyourinsitution.edu/api/" token <- "your-secret-token" redcap_read(redcap_uri=uri, token=token)$data
Alternatively, a redcap_project
object can be declared initially, which makes subsequent calls cleaner when the token and url are required only the when the object is declared. ```r library(REDCapR) #Load the package into the current R session, if you haven’t already. uri <- “https://bbmc.ouhsc.edu/redcap/api/” token <- “9A81268476645C4E5F03428B8AC3AA7B” project <- redcap_project$new(redcap_uri=uri, token=token)
ds_three_columns <- project\(read(fields=c("record_id", "sex", "age"))\)data
-ids_of_males <- ds_three_columns\(record_id[ds_three_columns\)sex==1] ids_of_minors <- ds_three_columns\(record_id[ds_three_columns\)age < 18]
-ds_males <- project\(read(records=ids_of_males, batch_size=2)\)data ds_minors <- project\(read(records=ids_of_minors)\)data ```
+Can the user export from their own project? The code is similar to the previous check, but the uri
and token
values will need to be modified.
library(REDCapR) #Load the package into the current R session, if you haven't already.
+redcap_uri <- "https://the.urlofyourinsitution.edu/api/"
+token <- "your-secret-token"
+redcap_read(redcap_uri=uri, token=token)$data
Alternatively, a redcap_project
object can be declared initially, which makes subsequent calls cleaner when the token and url are required only the when the object is declared.
library(REDCapR) #Load the package into the current R session, if you haven't already.
+uri <- "https://bbmc.ouhsc.edu/redcap/api/"
+token <- "9A81268476645C4E5F03428B8AC3AA7B"
+project <- redcap_project$new(redcap_uri=uri, token=token)
+
+ds_three_columns <- project$read(fields=c("record_id", "sex", "age"))$data
+
+ids_of_males <- ds_three_columns$record_id[ds_three_columns$sex==1]
+ids_of_minors <- ds_three_columns$record_id[ds_three_columns$age < 18]
+
+ds_males <- project$read(records=ids_of_males, batch_size=2)$data
+ds_minors <- project$read(records=ids_of_minors)$data
Is the export operation still unsuccessful using REDCapR? If so the “Can the user query a entire REDCap project using RCurl?” check succeeded, but the REDCapR checks did not, consider posting a new GitHub issue to the package developers.
If you’re not using redcapAPI, you can skip this section and proceed to ‘Importing into REDCap from R’ below. More specific discussion about redcapAPI
can be found at the package’s wiki.
Is redcapAPI installed on the user’s machine? Currently, the easiest way to install redcapAPI
is from CRAN. r install.packages("redcapAPI")
Developmental versions may be available on GitHub. r install.packages("devtools", repos="http://cran.rstudio.com") devtools::install_github(repo="nutterb/redcapAPI")
Is redcapAPI installed on the user’s machine? Currently, the easiest way to install redcapAPI
is from CRAN.
Developmental versions may be available on GitHub.
+ +Does redcapAPI load successfully on the user’s machine? If so, running library(redcapAPI)
should produce the following output if you’re starting with a fresh session of R:
Does redcapAPI load successfully on the user’s machine? If so, running library(redcapAPI)
should produce the following output if you’re starting with a fresh session of R: r library(redcapAPI) ## Loading required package: redcapAPI
Can the user export from an example project? This is the same fake data hosted by the OUHSC BBMC as in the previous section. r library(redcapAPI) #Load the package into the current R session. rcon <- redcapConnection( url = "https://bbmc.ouhsc.edu/redcap/api/", token = "9A81268476645C4E5F03428B8AC3AA7B" ) exportRecords(rcon)
The previous code should produce similar output. Notice there are five rows and the columns will wrap around if your console window is too narrow. ``` record_id name_first name_last address telephone email 1 1 Nutmeg Nutmouse 14 Rose Cottage St.UK, 323232 (432) 456-4848 nutty@mouse.com 2 2 Tumtum Nutmouse 14 Rose Cottage Blvd.UK 34243 (234) 234-2343 tummy@mouse.comm 3 3 Marcus Wood 243 Hill St.OK 73402 (433) 435-9865 mw@mwood.net 4 4 Trudy DAG 342 ElmTX, 75116 (987) 654-3210 peroxide@blonde.com 5 5 John Lee Walker Hotel SuiteOrleans LA, 70115 (333) 333-4444 left@hippocket.com
- dob age ethnicity race sex height weight bmi
-1 2003-08-30 10 1 2 0 5.00 1 400.0 2 2003-03-10 10 1 6 1 6.00 1 277.8 3 1934-04-09 79 0 4 1 180.00 80 24.7 4 1952-11-02 61 1 4 0 165.00 54 19.8 5 1955-04-15 58 1 4 1 193.04 104 27.9
- comments
-1 Character in a book, with some guessing 2 A mouse character from a good book 3 completely made up 4 This record doesn’t have a DAG assignedcall up Trudy on the telephoneher a letter in the mail 5 Had a hand for trouble and a eye for cashhad a gold watch chain and a black mustache
-demographics_complete 1 2 2 2 3 2 4 2 5 2 ```
+Can the user export from an example project? This is the same fake data hosted by the OUHSC BBMC as in the previous section.
+library(redcapAPI) #Load the package into the current R session.
+rcon <- redcapConnection(
+ url = "https://bbmc.ouhsc.edu/redcap/api/",
+ token = "9A81268476645C4E5F03428B8AC3AA7B"
+)
+exportRecords(rcon)
The previous code should produce similar output. Notice there are five rows and the columns will wrap around if your console window is too narrow.
+record_id name_first name_last address telephone email
+1 1 Nutmeg Nutmouse 14 Rose Cottage St.\nKenning UK, 323232 (432) 456-4848 nutty@mouse.com
+2 2 Tumtum Nutmouse 14 Rose Cottage Blvd.\nKenning UK 34243 (234) 234-2343 tummy@mouse.comm
+3 3 Marcus Wood 243 Hill St.\nGuthrie OK 73402 (433) 435-9865 mw@mwood.net
+4 4 Trudy DAG 342 Elm\nDuncanville TX, 75116 (987) 654-3210 peroxide@blonde.com
+5 5 John Lee Walker Hotel Suite\nNew Orleans LA, 70115 (333) 333-4444 left@hippocket.com
+
+ dob age ethnicity race sex height weight bmi
+1 2003-08-30 10 1 2 0 5.00 1 400.0
+2 2003-03-10 10 1 6 1 6.00 1 277.8
+3 1934-04-09 79 0 4 1 180.00 80 24.7
+4 1952-11-02 61 1 4 0 165.00 54 19.8
+5 1955-04-15 58 1 4 1 193.04 104 27.9
+
+ comments
+1 Character in a book, with some guessing
+2 A mouse character from a good book
+3 completely made up
+4 This record doesn't have a DAG assigned\n\nSo call up Trudy on the telephone\nSend her a letter in the mail
+5 Had a hand for trouble and a eye for cash\n\nHe had a gold watch chain and a black mustache
+
+demographics_complete
+1 2
+2 2
+3 2
+4 2
+5 2
+Can the user export from their own project? The code is similar to the previous check, but the uri
and token
values will need to be modified.
Can the user export from their own project? The code is similar to the previous check, but the uri
and token
values will need to be modified. r library(redcapAPI) #Load the package into the current R session, if you haven't already. rcon <- redcapConnection( url = "https://the.urlofyourinsitution.edu/api/", # Adapt this to your server. token = "your-secret-token" # Adapt this to your user's token. ) exportRecords(rcon)
Is the export operation still unsuccessful using redcapAPI? If so the “Can the user query a entire REDCap project using RCurl?” check succeeded, but the redcapAPI checks did not, consider posting a new GitHub issue to the package developers.
http://<*your server name*>/redcap/api/help
+The basic API documentation is available on your REDCap server, typically at
+http://<*your server name*>/redcap/api/help
API Help Page
and `API Examples’ pages on the REDCap wiki (i.e., https://community.projectredcap.org/articles/456/api-documentation.html and https://community.projectredcap.org/articles/462/api-examples.html). If you do not have an account for the wiki, please ask your campus REDCap administrator to send you the static material.In addition to this troubleshooting document, REDCapR has a vignette that covers its basic operations.
vignettes/advanced-redcapr-operations.Rmd
advanced-redcapr-operations.Rmd
#> 18 records and 125 columns were read from REDCap in 0.6 seconds. The http status code was 200.
+#> 18 records and 125 columns were read from REDCap in 0.3 seconds. The http status code was 200.
#> study_id redcap_event_name pmq1 pmq2 pmq3 pmq4
@@ -252,14 +252,14 @@
token = token_simple,
config_options = config_options
)$data
-#> 5 records and 24 columns were read from REDCap in 0.5 seconds. The http status code was 200.
+#> 5 records and 24 columns were read from REDCap in 0.3 seconds. The http status code was 200.
config_options <- list(ssl.verifypeer=FALSE)
ds_no_ssl <- redcap_read_oneshot(
redcap_uri = uri,
token = token_simple,
config_options = config_options
)$data
#> 5 records and 24 columns were read from REDCap in 0.5 seconds. The http status code was 200.
+#> 5 records and 24 columns were read from REDCap in 0.2 seconds. The http status code was 200.
Report rendered by wibeasley at 2019-09-20, 18:17 -0600 in 5 seconds.
+Report rendered by wibeasley at 2019-09-22, 15:37 -0500 in 4 seconds.
We’ve been using R with REDCap’s API since 2012 and have developed REDCapR
. Before encapsulating these functions in a package, we were replicating 50+ lines of code to contact REDCap and robustly transform the returned csv into an R data.frame
; it took twice that much to implement batching. All this can be done in one call to redcap_read()
:
We’ve been using R with REDCap’s API since 2012 and have developed REDCapR
. Before encapsulating these functions in a package, we were replicating 50+ lines of code to contact REDCap and robustly transform the returned csv into an R data.frame
; it took twice that much to implement batching. All this can be done in one call to redcap_read()
:
The redcap_read()
function also accepts values for subsetting/filtering the records and fields. Here are two examples; the first selects only a portion of the rows, while the second selects only a portion of the columns. Documentation for the additional 20+ functions are found at ouhscbbmc.github.io/REDCapR/reference.
# Return only records with IDs of 1 and 4
@@ -148,7 +148,7 @@
Collaborative Development
-We encourage input and collaboration. If you’re familiar with GitHub and R packages, feel free to submit a pull request. If you’d like to report a bug or make a suggestion, please create a GitHub issue; issues are a usually a good place to ask public questions too. However, feel free to email Will (wibeasley@hotmail.com). Please note that this project is released with a Contributor Code of Conduct; by participating in this project you agree to abide by its terms. We have some starting material described in the ./documentation-for-developers/
directory.
+We encourage input and collaboration. If you’re familiar with GitHub and R packages, feel free to submit a pull request. If you’d like to report a bug or make a suggestion, please create a GitHub issue; issues are a usually a good place to ask public questions too. However, feel free to email Will (wibeasley@hotmail.com). Please note that this project is released with a Contributor Code of Conduct; by participating in this project you agree to abide by its terms. We have some starting material described in the ./documentation-for-developers/
directory.
We’d like to thank the following developers for their advice and code contributions: Benjamin Nutter, Rollie Parrish, Scott Burns, John Aponte, Andrew Peters, and Hao Zhu.
diff --git a/docs/news/index.html b/docs/news/index.html
index f85771cc..9820f475 100644
--- a/docs/news/index.html
+++ b/docs/news/index.html
@@ -82,7 +82,7 @@
@@ -152,9 +152,9 @@
Changelog
Source: NEWS.md
+REDCapR::redcap_next_free_record_name(redcap_uri=uri, token=token) # Should return "6"uri <- "https://bbmc.ouhsc.edu/redcap/api/" token <- "9A81268476645C4E5F03428B8AC3AA7B" -REDCapR::redcap_next_free_record_name(redcap_uri=uri, token=token) # Should return "6"#>#> [1] "6"
diff --git a/docs/reference/redcap_write_oneshot.html b/docs/reference/redcap_write_oneshot.html index 2f868fcb..42ff6581 100644 --- a/docs/reference/redcap_write_oneshot.html +++ b/docs/reference/redcap_write_oneshot.html @@ -83,7 +83,7 @@ diff --git a/docs/reference/replace_nas_with_explicit.html b/docs/reference/replace_nas_with_explicit.html index f322c42f..3e97c114 100644 --- a/docs/reference/replace_nas_with_explicit.html +++ b/docs/reference/replace_nas_with_explicit.html @@ -85,7 +85,7 @@ diff --git a/docs/reference/retrieve_credential.html b/docs/reference/retrieve_credential.html index 5df6a4db..9d9502c8 100644 --- a/docs/reference/retrieve_credential.html +++ b/docs/reference/retrieve_credential.html @@ -83,7 +83,7 @@ diff --git a/docs/reference/sanitize_token.html b/docs/reference/sanitize_token.html index a4b40a02..026c5d24 100644 --- a/docs/reference/sanitize_token.html +++ b/docs/reference/sanitize_token.html @@ -84,7 +84,7 @@ diff --git a/docs/reference/validate.html b/docs/reference/validate.html index 91d71218..bfe011eb 100644 --- a/docs/reference/validate.html +++ b/docs/reference/validate.html @@ -83,7 +83,7 @@ diff --git a/utility/refresh.R b/utility/refresh.R index 368bd6e0..7ea78e3d 100644 --- a/utility/refresh.R +++ b/utility/refresh.R @@ -22,5 +22,5 @@ test_results_not_checked <- testthat::test_dir("./tests/manual/") devtools::check(cran=T) # devtools::check_rhub(email="wibeasley@hotmail.com") # devtools::check_win_devel() # CRAN submission policies encourage the development version -# devtools::revdep_check(pkg="REDCapR", recursive=TRUE) +# devtools::revdepcheck(recursive=TRUE) # devtools::release(check=FALSE) #Careful, the last question ultimately uploads it to CRAN, where you can't delete/reverse your decision. diff --git a/vignettes/TroubleshootingApiCalls.Rmd b/vignettes/TroubleshootingApiCalls.Rmd index 8ebfea3e..b173d44f 100644 --- a/vignettes/TroubleshootingApiCalls.Rmd +++ b/vignettes/TroubleshootingApiCalls.Rmd @@ -74,6 +74,7 @@ This section group examines potential problems that occur after it leaves a work 1. **Can an user query the API successfully with Postman with the their own token?** The values they enter should be exactly the same as those entered in the previous step. A failure here (assuming the previous step was successful) suggests a network or firewall issue. If the server is behind your institution's firewall, verify the user is connecting successfully through the VPN. 1. **Can a user query the API with cURL?** [cURL](http://curl.haxx.se/docs/manpage.html) is a command line tool that's underneath a lot of libraries. If it's installed correctly on your location machine, it can be executed from the terminal or command line. + ```shell curl -X POST -H "Cache-Control: no-cache" -F "token=9A81268476645C4E5F03428B8AC3AA7B" -F "content=record" -F "format=csv" "https://bbmc.ouhsc.edu/redcap/api/" ``` @@ -189,18 +190,21 @@ Exporting from REDCap to R, using REDCapR If you're not using REDCapR, you can skip this section and proceed to 'Importing into REDCap from R' below. 1. **Is REDCapR installed on the user's machine?** Currently the easiest way to install REDCapR is with the [devtools](https://github.com/hadley/devtools). The follow code installs devtools, then installs REDCapR. + ```r install.packages("devtools", repos="http://cran.rstudio.com") - devtools::install_github(repo="OuhscBbmc/REDCapR") + remotes::install_github(repo="OuhscBbmc/REDCapR") ``` 1. **Does REDCapR load successfully on the user's machine?** If so, running `library(REDCapR)` should produce the following output if you're starting with a fresh session of R: + ```r library(REDCapR) ## Loading required package: REDCapR ``` 1. **Can the user export from an example project?** This is the same fake data hosted by the [OUHSC BBMC](http://ouhsc.edu/bbmc/) as in the previous section. + ```r library(REDCapR) #Load the package into the current R session. uri <- "https://bbmc.ouhsc.edu/redcap/api/" @@ -209,6 +213,7 @@ If you're not using REDCapR, you can skip this section and proceed to 'Importing ``` The previous code should produce similar output. Notice there are five rows and the columns will wrap around if your console window is too narrow. + ``` 5 records and 1 columns were read from REDCap in 0.41 seconds. Starting to read 5 records at 2014-06-27 17:19:49 @@ -245,6 +250,7 @@ If you're not using REDCapR, you can skip this section and proceed to 'Importing ``` 1. **Can the user export from their own project?** The code is similar to the previous check, but the `uri` and `token` values will need to be modified. + ```r library(REDCapR) #Load the package into the current R session, if you haven't already. redcap_uri <- "https://the.urlofyourinsitution.edu/api/" @@ -253,6 +259,7 @@ If you're not using REDCapR, you can skip this section and proceed to 'Importing ``` Alternatively, a `redcap_project` object can be declared initially, which makes subsequent calls cleaner when the token and url are required only the when the object is declared. + ```r library(REDCapR) #Load the package into the current R session, if you haven't already. uri <- "https://bbmc.ouhsc.edu/redcap/api/" @@ -279,23 +286,27 @@ Exporting from REDCap to R, using redcapAPI If you're not using redcapAPI, you can skip this section and proceed to 'Importing into REDCap from R' below. More specific discussion about `redcapAPI` can be found at the [package's wiki](https://github.com/nutterb/redcapAPI/wiki). 1. **Is redcapAPI installed on the user's machine?** Currently, the easiest way to install `redcapAPI` is from CRAN. + ```r install.packages("redcapAPI") ``` Developmental versions may be available on GitHub. + ```r install.packages("devtools", repos="http://cran.rstudio.com") - devtools::install_github(repo="nutterb/redcapAPI") + remotes::install_github(repo="nutterb/redcapAPI") ``` 1. **Does redcapAPI load successfully on the user's machine?** If so, running `library(redcapAPI)` should produce the following output if you're starting with a fresh session of R: + ```r library(redcapAPI) ## Loading required package: redcapAPI ``` 1. **Can the user export from an example project?** This is the same fake data hosted by the [OUHSC BBMC](http://ouhsc.edu/bbmc/) as in the previous section. + ```r library(redcapAPI) #Load the package into the current R session. rcon <- redcapConnection( @@ -306,6 +317,7 @@ If you're not using redcapAPI, you can skip this section and proceed to 'Importi ``` The previous code should produce similar output. Notice there are five rows and the columns will wrap around if your console window is too narrow. + ``` record_id name_first name_last address telephone email 1 1 Nutmeg Nutmouse 14 Rose Cottage St.\nKenning UK, 323232 (432) 456-4848 nutty@mouse.com @@ -337,6 +349,7 @@ If you're not using redcapAPI, you can skip this section and proceed to 'Importi ``` 1. **Can the user export from their own project?** The code is similar to the previous check, but the `uri` and `token` values will need to be modified. + ``` r library(redcapAPI) #Load the package into the current R session, if you haven't already. rcon <- redcapConnection( @@ -380,9 +393,11 @@ Other good resources ------------------------------------------------------------------ * The basic API documentation is available on your REDCap server, typically at + ``` http://<*your server name*>/redcap/api/help ``` + * If you have access to the REDCap wiki, some newer examples might exist aturi <- "https://bbmc.ouhsc.edu/redcap/api/" token <- "06DEFB601F9B46847DAA9DF0CFA951B4" -result <- REDCapR::redcap_users_export(redcap_uri=uri, token=token)#>result$data_user#> # A tibble: 2 x 31 +result <- REDCapR::redcap_users_export(redcap_uri=uri, token=token)#>result$data_user#> # A tibble: 2 x 31 #> username email firstname lastname expiration data_access_gro… data_access_gro… #> <chr> <chr> <chr> <chr> <date> <chr> <chr> #> 1 unittes… wibe… Unit Test PHI Free NA daga 331 diff --git a/docs/reference/redcap_variables.html b/docs/reference/redcap_variables.html index a18e15be..5156abc6 100644 --- a/docs/reference/redcap_variables.html +++ b/docs/reference/redcap_variables.html @@ -83,7 +83,7 @@diff --git a/docs/reference/redcap_version.html b/docs/reference/redcap_version.html index a20bd94a..c8a95dd2 100644 --- a/docs/reference/redcap_version.html +++ b/docs/reference/redcap_version.html @@ -83,7 +83,7 @@ @@ -194,7 +194,7 @@Details
Examples
+REDCapR::redcap_version(redcap_uri=uri, token=token)uri <- "https://bbmc.ouhsc.edu/redcap/api/" token <- "9A81268476645C4E5F03428B8AC3AA7B" -REDCapR::redcap_version(redcap_uri=uri, token=token)#>#> [1] ‘9.0.0’#>#> [1] ‘9.0.0’