Skip to content

Commit

Permalink
resuable fxs filter_logic_prepare() & verbose_prepare()
Browse files Browse the repository at this point in the history
helps keep the order consistent ref #204
  • Loading branch information
wibeasley committed May 30, 2018
1 parent 8c788a8 commit bd88aea
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion R/redcap-download-file-oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ redcap_download_file_oneshot <- function(
checkmate::assert_character(token , any.missing=F, len=1, pattern="^.{1,}$")

token <- sanitize_token(token)
verbose <- ifelse(!is.null(verbose), verbose, getOption("verbose"))
verbose <- verbose_prepare(verbose)

post_body <- list(
token = token,
Expand Down
2 changes: 1 addition & 1 deletion R/redcap-metadata-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ redcap_metadata_read <- function(
token <- sanitize_token(token)
fields_collapsed <- collapse_vector(fields , fields_collapsed)
forms_collapsed <- collapse_vector(forms , forms_collapsed)
verbose <- ifelse(!is.null(verbose), verbose, getOption("verbose"))
verbose <- verbose_prepare(verbose)

post_body <- list(
token = token,
Expand Down
7 changes: 2 additions & 5 deletions R/redcap-read-oneshot-eav.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,8 @@ redcap_read_oneshot_eav <- function(
forms_collapsed <- collapse_vector(forms , forms_collapsed)
events_collapsed <- collapse_vector(events , events_collapsed)
export_data_access_groups <- ifelse(export_data_access_groups, "true", "false")

if( all(nchar(filter_logic)==0) )
filter_logic <- ifelse(is.null(filter_logic), "", filter_logic) #This is an empty string if `filter_logic` is NULL.

verbose <- ifelse(!is.null(verbose), verbose, getOption("verbose"))
filter_logic <- filter_logic_prepare(filter_logic)
verbose <- verbose_prepare(verbose)

if( any(grepl("[A-Z]", fields_collapsed)) )
warning("The fields passed to REDCap appear to have at least uppercase letter. REDCap variable names are snake case.")
Expand Down
7 changes: 2 additions & 5 deletions R/redcap-read-oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,8 @@ redcap_read_oneshot <- function(
fields_collapsed <- collapse_vector(fields , fields_collapsed)
forms_collapsed <- collapse_vector(forms , forms_collapsed)
events_collapsed <- collapse_vector(events , events_collapsed)

if( all(nchar(filter_logic)==0) )
filter_logic <- ifelse(is.null(filter_logic), "", filter_logic) #This is an empty string if `filter_logic` is NULL.

verbose <- ifelse(!is.null(verbose), verbose, getOption("verbose"))
filter_logic <- filter_logic_prepare(filter_logic)
verbose <- verbose_prepare(verbose)

if( any(grepl("[A-Z]", fields_collapsed)) )
warning("The fields passed to REDCap appear to have at least uppercase letter. REDCap variable names are snake case.")
Expand Down
7 changes: 2 additions & 5 deletions R/redcap-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,8 @@ redcap_read <- function(
fields_collapsed <- collapse_vector(fields , fields_collapsed)
forms_collapsed <- collapse_vector(forms , forms_collapsed)
events_collapsed <- collapse_vector(events , events_collapsed)

if( all(nchar(filter_logic)==0) )
filter_logic <- ifelse(is.null(filter_logic), "", filter_logic) #This is an empty string if `filter_logic` is NULL.

verbose <- ifelse(!is.null(verbose), verbose, getOption("verbose"))
filter_logic <- filter_logic_prepare(filter_logic)
verbose <- verbose_prepare(verbose)

start_time <- Sys.time()

Expand Down
2 changes: 1 addition & 1 deletion R/redcap-upload-file-oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ redcap_upload_file_oneshot <- function(
checkmate::assert_character(token , any.missing=F, len=1, pattern="^.{1,}$")

token <- sanitize_token(token)
verbose <- ifelse(!is.null(verbose), verbose, getOption("verbose"))
verbose <- verbose_prepare(verbose)

if( verbose )
message("Preparing to upload the file `", file_name, "`.")
Expand Down
2 changes: 1 addition & 1 deletion R/redcap-variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ redcap_variables <- function(
checkmate::assert_character(token , any.missing=F, len=1, pattern="^.{1,}$")

token <- sanitize_token(token)
verbose <- ifelse(!is.null(verbose), verbose, getOption("verbose"))
verbose <- verbose_prepare(verbose)

post_body <- list(
token = token,
Expand Down
2 changes: 1 addition & 1 deletion R/redcap-version.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ redcap_version <- function( redcap_uri, token, verbose=TRUE, config_options=NULL
checkmate::assert_character(token , any.missing=F, len=1, pattern="^.{1,}$")

token <- sanitize_token(token)
verbose <- ifelse(!is.null(verbose), verbose, getOption("verbose"))
verbose <- verbose_prepare(verbose)

post_body <- list(
token = token,
Expand Down
2 changes: 1 addition & 1 deletion R/redcap-write-oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ redcap_write_oneshot <- function(
checkmate::assert_character(token , any.missing=F, len=1, pattern="^.{1,}$")

token <- sanitize_token(token)
verbose <- ifelse(!is.null(verbose), verbose, getOption("verbose"))
verbose <- verbose_prepare(verbose)

con <- base::textConnection(object='csv_elements', open='w', local=TRUE)
utils::write.csv(ds, con, row.names = FALSE, na="")
Expand Down
2 changes: 1 addition & 1 deletion R/redcap-write.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ redcap_write <- function(
checkmate::assert_character(token , any.missing=F, len=1, pattern="^.{1,}$")

token <- sanitize_token(token)
verbose <- ifelse(!is.null(verbose), verbose, getOption("verbose"))
verbose <- verbose_prepare(verbose)

ds_glossary <- REDCapR::create_batch_glossary(row_count=base::nrow(ds_to_write), batch_size=batch_size)

Expand Down
10 changes: 10 additions & 0 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,13 @@ collapse_vector <- function( elements, collapsed ) {

return( collapsed )
}

filter_logic_prepare <- function( filter_logic ) {
if( all(nchar(filter_logic)==0) )
filter_logic <- ifelse(is.null(filter_logic), "", filter_logic) #This is an empty string if `filter_logic` is NULL.
return( filter_logic )
}

verbose_prepare <- function( verbose ) {
ifelse(!is.null(verbose), verbose, getOption("verbose"))
}

0 comments on commit bd88aea

Please sign in to comment.