Skip to content

Commit

Permalink
Exposes config options in write operations. Partially addresses #58.
Browse files Browse the repository at this point in the history
  • Loading branch information
wibeasley committed Nov 2, 2014
1 parent 2c8a6c6 commit bbcaa42
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 50 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Description: Encapsulates functions to streamline calls from R to the REDCap
University. The Application Programming Interface (API) offers an avenue
to access and modify data programmatically, improving the capacity for
literate and reproducible programming.
Version: 0.5-18
Version: 0.5-19
Date: 2014-10-07
Authors@R: c(person("Will", "Beasley", role = c("aut", "cre"), email =
"[email protected]"), person("David", "Bard", role = "ctb"),
Expand Down
Binary file modified DocumentationPeek.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions R/redcap_project.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ redcap_project <- setRefClass(
write = function(
ds_to_write,
batch_size = 100L, interbatch_delay = 0,
verbose = TRUE, cert_location = NULL) {
verbose = TRUE, config_options = NULL) {

"Imports records to a REDCap project."

return( REDCapR::redcap_write(
ds_to_write = ds_to_write,
batch_size = batch_size, interbatch_delay = interbatch_delay,
redcap_uri = redcap_uri, token = token,
verbose = verbose, cert_location=cert_location
config_options = config_options
))
}

Expand Down
2 changes: 1 addition & 1 deletion R/redcap_read.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#' @param export_data_access_groups A boolean value that specifies whether or not to export the ``redcap_data_access_group'' field when data access groups are utilized in the project. Default is \code{FALSE}. See the details below.
#' @param raw_or_label A string (either \code{'raw'} or \code{'label'} that specifies whether to export the raw coded values or the labels for the options of multiple choice fields. Default is \code{'raw'}.
#' @param verbose A boolean value indicating if \code{message}s should be printed to the R console during the operation. The verbose output might contain sensitive information (\emph{e.g.} PHI), so turn this off if the output might be visible somewhere public. Optional.
#' @param config_options A list of options to pass to \code{POST} method in the \code{httr} package. See the details below. Optional.
#' @param config_options A list of options to pass to \code{POST} method in the \code{httr} package. See the details in \code{redcap_read_oneshot()} Optional.
#' @param id_position The column position of the variable that unique identifies the subject. This defaults to the first variable in the dataset.
#'
#' @return Currently, a list is returned with the following elements,
Expand Down
14 changes: 5 additions & 9 deletions R/redcap_read_oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,14 @@ redcap_read_oneshot <- function( redcap_uri, token, records=NULL, records_collap

if( missing( config_options ) | is.null(config_options) ) {
cert_location <- system.file("ssl_certs/mozilla_ca_root.crt", package="REDCapR")

if( !base::file.exists(cert_location) )
stop(paste0("The file specified by `cert_location`, (", cert_location, ") could not be found."))

config_options <- list(cainfo=cert_location)
}
# #cert_location <- system.file("cacert.pem", package="httr")
# cert_location <- system.file("ssl_certs/mozilla_ca_root.crt", package="REDCapR")
# # curl_options <- RCurl::curlOptions(ssl.verifypeer=FALSE)

if( !base::file.exists(cert_location) )
stop(paste0("The file specified by `cert_location`, (", cert_location, ") could not be found."))


#curl_options <- RCurl::curlOptions(cainfo=cert_location, sslversion=3)
# config_options <- list(cainfo=cert_location, sslversion=sslversion)

# raw_text <- RCurl::postForm(
# uri = redcap_uri
# , token = token
Expand Down
9 changes: 3 additions & 6 deletions R/redcap_write.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap project. Required.
#' @param token The user-specific string that serves as the password for a project. Required.
#' @param verbose A boolean value indicating if \code{message}s should be printed to the R console during the operation. The verbose output might contain sensitive information (\emph{e.g.} PHI), so turn this off if the output might be visible somewhere public. Optional.
#' @param cert_location If present, this string should point to the location of the cert files required for SSL verification. If the value is missing or NULL, the server's identity will be verified using a recent CA bundle from the \href{http://curl.haxx.se}{cURL website}. See the details below. Optional.
#' @param sslversion The SSL version for curl. The default is 3. Set to NULL if your server has disabled SSL v3.
#' @param config_options A list of options to pass to \code{POST} method in the \code{httr} package. See the details in \code{redcap_read_oneshot()} Optional.
#'
#' @return Currently, a list is returned with the following elements,
#' \enumerate{
Expand Down Expand Up @@ -75,8 +74,7 @@ redcap_write <- function( ds_to_write,
continue_on_error = FALSE,
redcap_uri,
token,
verbose = TRUE, cert_location=NULL,
sslversion = 3) {
verbose = TRUE, config_options = NULL) {

if( base::missing(redcap_uri) )
base::stop("The required parameter `redcap_uri` was missing from the call to `redcap_write()`.")
Expand Down Expand Up @@ -105,8 +103,7 @@ redcap_write <- function( ds_to_write,
redcap_uri = redcap_uri,
token = token,
verbose = verbose,
cert_location=cert_location,
sslversion=sslversion)
config_options = config_options)

lst_status_code[[i]] <- write_result$status_code
# lst_status_message[[i]] <- write_result$status_message
Expand Down
18 changes: 9 additions & 9 deletions R/redcap_write_oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#' @param redcap_uri The URI (uniform resource identifier) of the REDCap project. Required.
#' @param token The user-specific string that serves as the password for a project. Required.
#' @param verbose A boolean value indicating if \code{message}s should be printed to the R console during the operation. The verbose output might contain sensitive information (\emph{e.g.} PHI), so turn this off if the output might be visible somewhere public. Optional.
#' @param cert_location If present, this string should point to the location of the cert files required for SSL verification. If the value is missing or NULL, the server's identity will be verified using a recent CA bundle from the \href{http://curl.haxx.se}{cURL website}. See the details below. Optional.
#' @param sslversion The SSL version for curl. The default is 3. Set to NULL if your server has disabled SSL v3.
#' @param config_options A list of options to pass to \code{POST} method in the \code{httr} package. See the details in \code{redcap_read_oneshot()} Optional.
#'
#' @return Currently, a list is returned with the following elements,
#' \enumerate{
Expand Down Expand Up @@ -69,7 +68,7 @@
#' }
#'

redcap_write_oneshot <- function( ds, redcap_uri, token, verbose=TRUE, cert_location=NULL, sslversion=3 ) {
redcap_write_oneshot <- function( ds, redcap_uri, token, verbose=TRUE, config_options=NULL ) {
#TODO: automatically convert boolean/logical class to integer/bit class
start_time <- Sys.time()
csvElements <- NULL #This prevents the R CHECK NOTE: 'No visible binding for global variable Note in R CMD check'; Also see if( getRversion() >= "2.15.1" ) utils::globalVariables(names=c("csvElements")) #http://stackoverflow.com/questions/8096313/no-visible-binding-for-global-variable-note-in-r-cmd-check; http://stackoverflow.com/questions/9439256/how-can-i-handle-r-cmd-check-no-visible-binding-for-global-variable-notes-when
Expand All @@ -80,13 +79,14 @@ redcap_write_oneshot <- function( ds, redcap_uri, token, verbose=TRUE, cert_loca
if( missing(token) )
stop("The required parameter `token` was missing from the call to `redcap_write_oneshot()`.")

if( missing( cert_location ) | is.null(cert_location) )
if( missing( config_options ) | is.null(config_options) ) {
cert_location <- system.file("ssl_certs/mozilla_ca_root.crt", package="REDCapR")

if( !base::file.exists(cert_location) )
stop(paste0("The file specified by `cert_location`, (", cert_location, ") could not be found."))

config_options <- list(cainfo=cert_location, sslversion=sslversion)

if( !base::file.exists(cert_location) )
stop(paste0("The file specified by `cert_location`, (", cert_location, ") could not be found."))

config_options <- list(cainfo=cert_location)
}

con <- base::textConnection(object='csvElements', open='w', local=TRUE)
write.csv(ds, con, row.names = FALSE, na="")
Expand Down
2 changes: 1 addition & 1 deletion man/redcap_project.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ functionality
config_options = NULL)}}{Exports records from a REDCap project.}

\item{\code{write(ds_to_write, batch_size = 100L, interbatch_delay = 0,
verbose = TRUE, cert_location = NULL)}}{Imports records to a REDCap project.}
verbose = TRUE, config_options = NULL)}}{Imports records to a REDCap project.}
}}
\examples{
library(REDCapR) #Load the package into the current R session.
Expand Down
2 changes: 1 addition & 1 deletion man/redcap_read.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ redcap_read(batch_size = 100L, interbatch_delay = 0.5,

\item{config_options}{A list of options to pass to
\code{POST} method in the \code{httr} package. See the
details below. Optional.}
details in \code{redcap_read_oneshot()} Optional.}

\item{id_position}{The column position of the variable
that unique identifies the subject. This defaults to the
Expand Down
14 changes: 4 additions & 10 deletions man/redcap_write.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
\usage{
redcap_write(ds_to_write, batch_size = 100L, interbatch_delay = 0.5,
continue_on_error = FALSE, redcap_uri, token, verbose = TRUE,
cert_location = NULL, sslversion = 3)
config_options = NULL)
}
\arguments{
\item{ds_to_write}{The \code{data.frame} to be imported
Expand Down Expand Up @@ -36,15 +36,9 @@ redcap_write(ds_to_write, batch_size = 100L, interbatch_delay = 0.5,
if the output might be visible somewhere public.
Optional.}

\item{cert_location}{If present, this string should point
to the location of the cert files required for SSL
verification. If the value is missing or NULL, the
server's identity will be verified using a recent CA
bundle from the \href{http://curl.haxx.se}{cURL website}.
See the details below. Optional.}
\item{sslversion}{The SSL version for curl. The default
is 3. Set to NULL if your server has disabled SSL v3.}
\item{config_options}{A list of options to pass to
\code{POST} method in the \code{httr} package. See the
details in \code{redcap_read_oneshot()} Optional.}
}
\value{
Currently, a list is returned with the following elements,
Expand Down
14 changes: 4 additions & 10 deletions man/redcap_write_oneshot.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
\title{Write/Import records to a REDCap project.}
\usage{
redcap_write_oneshot(ds, redcap_uri, token, verbose = TRUE,
cert_location = NULL, sslversion = 3)
config_options = NULL)
}
\arguments{
\item{ds}{The \code{data.frame} to be imported into the
Expand All @@ -23,15 +23,9 @@ redcap_write_oneshot(ds, redcap_uri, token, verbose = TRUE,
if the output might be visible somewhere public.
Optional.}

\item{cert_location}{If present, this string should point
to the location of the cert files required for SSL
verification. If the value is missing or NULL, the
server's identity will be verified using a recent CA
bundle from the \href{http://curl.haxx.se}{cURL website}.
See the details below. Optional.}
\item{sslversion}{The SSL version for curl. The default
is 3. Set to NULL if your server has disabled SSL v3.}
\item{config_options}{A list of options to pass to
\code{POST} method in the \code{httr} package. See the
details in \code{redcap_read_oneshot()} Optional.}
}
\value{
Currently, a list is returned with the following elements,
Expand Down

0 comments on commit bbcaa42

Please sign in to comment.