Skip to content

Commit

Permalink
Connect collapse_vector()
Browse files Browse the repository at this point in the history
closes #209
  • Loading branch information
wibeasley committed May 29, 2018
1 parent a5eefe5 commit b096bb0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 28 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Modified Internals:
* `data.table::rbindlist()` replaced by `dplyr::bind_rows()`
* updated to readr 1.2.0 (#200)
* the checkmate package inspects most function parameters now (instead of `testit::assert()` and `base:stop()` ) (#190 & #208).
* `collapse_vector()` is refactored and tested (#209)

Deprecated Features:
* `retrieve_token_mssql()`, because `retrieve_credential_mssql()` is more general and more useful.
Expand Down
6 changes: 2 additions & 4 deletions R/redcap-metadata-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ redcap_metadata_read <- function(

token <- sanitize_token(token)

if( nchar(forms_collapsed)==0 )
forms_collapsed <- ifelse(is.null(forms), "", paste0(forms, collapse=",")) #This is an empty string if `forms` is NULL.
if( nchar(fields_collapsed)==0 )
fields_collapsed <- ifelse(is.null(fields), "", paste0(fields, collapse=",")) #This is an empty string if `fields` is NULL.
fields_collapsed <- collapse_vector(fields , fields_collapsed)
forms_collapsed <- collapse_vector(forms , forms_collapsed)

post_body <- list(
token = token,
Expand Down
13 changes: 5 additions & 8 deletions R/redcap-read-oneshot-eav.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,11 @@ redcap_read_oneshot_eav <- function(
token <- sanitize_token(token)
validate_field_names(fields)

if( all(nchar(records_collapsed)==0) )
records_collapsed <- ifelse(is.null(records), "", paste0(records, collapse=",")) #This is an empty string if `records` is NULL.
if( (length(fields_collapsed)==0L) | is.null(fields_collapsed) | all(nchar(fields_collapsed)==0L) )
fields_collapsed <- ifelse(is.null(fields), "", paste0(fields, collapse=",")) #This is an empty string if `fields` is NULL.
if( (length(forms_collapsed)==0L) | is.null(forms_collapsed) | all(nchar(forms_collapsed)==0L) )
forms_collapsed <- ifelse(is.null(forms), "", paste0(forms, collapse=",")) #This is an empty string if `forms` is NULL.
if( all(nchar(events_collapsed)==0) )
events_collapsed <- ifelse(is.null(events), "", paste0(events, collapse=",")) #This is an empty string if `events` is NULL.
records_collapsed <- collapse_vector(records , records_collapsed)
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.

Expand Down
13 changes: 5 additions & 8 deletions R/redcap-read-oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,11 @@ redcap_read_oneshot <- function(
token <- sanitize_token(token)
validate_field_names(fields)

if( all(nchar(records_collapsed)==0) )
records_collapsed <- ifelse(is.null(records), "", paste0(records, collapse=",")) #This is an empty string if `records` is NULL.
if( (length(fields_collapsed)==0L) | is.null(fields_collapsed) | all(nchar(fields_collapsed)==0L) )
fields_collapsed <- ifelse(is.null(fields), "", paste0(fields, collapse=",")) #This is an empty string if `fields` is NULL.
if( (length(forms_collapsed)==0L) | is.null(forms_collapsed) | all(nchar(forms_collapsed)==0L) )
forms_collapsed <- ifelse(is.null(forms), "", paste0(forms, collapse=",")) #This is an empty string if `forms` is NULL.
if( all(nchar(events_collapsed)==0) )
events_collapsed <- ifelse(is.null(events), "", paste0(events, collapse=",")) #This is an empty string if `events` is NULL.
records_collapsed <- collapse_vector(records , records_collapsed)
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.

Expand Down
13 changes: 5 additions & 8 deletions R/redcap-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,11 @@ redcap_read <- function(
token <- sanitize_token(token)
validate_field_names(fields)

if( all(nchar(records_collapsed)==0) )
records_collapsed <- ifelse(is.null(records), "", paste0(records, collapse=",")) #This is an empty string if `records` is NULL.
if( (length(fields_collapsed)==0L) | is.null(fields_collapsed) | all(nchar(fields_collapsed)==0) )
fields_collapsed <- ifelse(is.null(fields), "", paste0(fields, collapse=",")) #This is an empty string if `fields` is NULL.
if( (length(forms_collapsed)==0L) | is.null(forms_collapsed) | all(nchar(forms_collapsed)==0L) )
forms_collapsed <- ifelse(is.null(forms), "", paste0(forms, collapse=",")) #This is an empty string if `forms` is NULL.
if( all(nchar(events_collapsed)==0) )
events_collapsed <- ifelse(is.null(events), "", paste0(events, collapse=",")) #This is an empty string if `events` is NULL.
records_collapsed <- collapse_vector(records , records_collapsed)
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.

Expand Down

0 comments on commit b096bb0

Please sign in to comment.