From 5a41ae0b08f8f1f1cb3beb5028e4922e5152f96a Mon Sep 17 00:00:00 2001 From: Will Beasley Date: Thu, 23 Mar 2017 23:54:48 -0500 Subject: [PATCH] integrate `sanitize_token()` Closes #144 --- R/redcap-read-oneshot.R | 2 +- R/redcap-read.R | 2 +- R/redcap-upload-file-oneshot.R | 2 +- R/redcap-write-oneshot.R | 3 ++- R/redcap-write.R | 6 +++--- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/R/redcap-read-oneshot.R b/R/redcap-read-oneshot.R index b5a36727..332af6e0 100644 --- a/R/redcap-read-oneshot.R +++ b/R/redcap-read-oneshot.R @@ -117,7 +117,7 @@ redcap_read_oneshot <- function( if( !(raw_or_label %in% c("raw", "label")) ) stop("The optional parameter `raw_or_label` must be either 'raw' or 'label'.") - token <- sub("\\n", "", token) + token <- sanitize_token(token) if( all(nchar(records_collapsed)==0) ) records_collapsed <- ifelse(is.null(records), "", paste0(records, collapse=",")) #This is an empty string if `records` is NULL. diff --git a/R/redcap-read.R b/R/redcap-read.R index 668c2d49..5692293b 100644 --- a/R/redcap-read.R +++ b/R/redcap-read.R @@ -83,7 +83,7 @@ redcap_read <- function( if( missing(token) ) stop("The required parameter `token` was missing from the call to `redcap_read()`.") - token <- sub("\\n", "", token) + token <- sanitize_token(token) if( all(nchar(records_collapsed)==0) ) records_collapsed <- ifelse(is.null(records), "", paste0(records, collapse=",")) #This is an empty string if `records` is NULL. diff --git a/R/redcap-upload-file-oneshot.R b/R/redcap-upload-file-oneshot.R index 5070922b..ec680fe0 100644 --- a/R/redcap-upload-file-oneshot.R +++ b/R/redcap-upload-file-oneshot.R @@ -82,7 +82,7 @@ redcap_upload_file_oneshot <- function( file_name, record, redcap_uri, token, fi if( missing(token) ) stop("The required parameter `token` was missing from the call to `redcap_upload_file_oneshot()`.") - token <- sub("\\n", "", token) + token <- sanitize_token(token) if( verbose ) message("Preparing to upload the file `", file_name, "`.") diff --git a/R/redcap-write-oneshot.R b/R/redcap-write-oneshot.R index ce993259..0b0a50fc 100644 --- a/R/redcap-write-oneshot.R +++ b/R/redcap-write-oneshot.R @@ -76,7 +76,8 @@ redcap_write_oneshot <- function( ds, redcap_uri, token, verbose=TRUE, config_op if( missing(token) ) stop("The required parameter `token` was missing from the call to `redcap_write_oneshot()`.") - token <- sub("\\n", "", token) + token <- sanitize_token(token) + con <- base::textConnection(object='csvElements', open='w', local=TRUE) utils::write.csv(ds, con, row.names = FALSE, na="") close(con) diff --git a/R/redcap-write.R b/R/redcap-write.R index f42a73fc..ba62dff3 100644 --- a/R/redcap-write.R +++ b/R/redcap-write.R @@ -84,15 +84,15 @@ redcap_write <- function( verbose = TRUE, config_options = NULL ) { + start_time <- base::Sys.time() + if( base::missing(redcap_uri) ) base::stop("The required parameter `redcap_uri` was missing from the call to `redcap_write()`.") if( base::missing(token) ) base::stop("The required parameter `token` was missing from the call to `redcap_write()`.") - start_time <- base::Sys.time() - - token <- sub("\\n", "", token) + token <- sanitize_token(token) ds_glossary <- REDCapR::create_batch_glossary(row_count=base::nrow(ds_to_write), batch_size=batch_size)