Skip to content

Commit

Permalink
force plumbing variables
Browse files Browse the repository at this point in the history
ref #439
  • Loading branch information
wibeasley committed Oct 8, 2022
1 parent 89d4943 commit 91dc988
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
14 changes: 9 additions & 5 deletions R/redcap-metadata-coltypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,9 @@ redcap_metadata_internal <- function(
d_proj <- REDCapR::redcap_project_info_read(redcap_uri, token, verbose = verbose, handle_httr = handle_httr)$data

# Determine status of autonumbering, instrument complete status, and decimal mark
.record_field <- d_var$original_field_name[1]
.record_field <- d_var$original_field_name[1] # The first field should always be the "record" identifier.
.autonumber <- d_proj$record_autonumbering_enabled[1]
.plumbing_possibles <- c(.record_field, "redcap_event_name", "redcap_repeat_instrument", "redcap_repeat_instance")
decimal_period <- (locale$decimal_mark == ".")
decimal_comma <- (locale$decimal_mark == ",")

Expand Down Expand Up @@ -346,11 +347,9 @@ redcap_metadata_internal <- function(
dplyr::select(-.data$form_order, -.data$field_order_within_form) %>%
tibble::add_row(d_again, .after = 1) %>%
dplyr::mutate(
plumbing = (.data$field_name %in% c("redcap_event_name", "redcap_repeat_instrument", "redcap_repeat_instance"))
plumbing = (.data$field_name %in% .plumbing_possibles)
)

d_meta$plumbing[1] <- TRUE # The first field should always be the "record" identifier.

# The types of variables that are in metadata, but NOT variables:
# setdiff(d_meta$field_name_base, d_var$original_field_name)
# [1] "signature" "file_upload" "descriptive"
Expand Down Expand Up @@ -461,6 +460,8 @@ redcap_metadata_internal <- function(
.data$plumbing
)

.plumbing_variables <- intersect(d$field_name, .plumbing_possibles)

decimal_period_any <- any(d_meta$vt %in% c("number", "number_1dp", "number_2dp", "number_3dp", "number_4dp" ))
decimal_comma_any <- any(d_meta$vt %in% c("number_comma_decimal", "number_1dp_comma_decimal", "number_2dp_comma_decimal", "number_3dp_comma_decimal", "number_4dp_comma_decimal"))

Expand All @@ -479,8 +480,11 @@ redcap_metadata_internal <- function(

list(
d_variable = d,
success = TRUE,
longitudinal = d_proj$is_longitudinal[1],
repeating = d_proj$has_repeating_instruments_or_events[1]
repeating = d_proj$has_repeating_instruments_or_events[1],
record_id_name = .record_field,
plumbing_variables = .plumbing_variables
)
}

Expand Down
14 changes: 4 additions & 10 deletions R/redcap-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -252,28 +252,22 @@ redcap_read <- function(

start_time <- Sys.time()

metadata <- REDCapR::redcap_metadata_read(
metadata <- REDCapR:::redcap_metadata_internal(
redcap_uri = redcap_uri,
token = token,
verbose = verbose,
config_options = config_options,
handle_httr = handle_httr
)

if (!metadata$success) {
error_message <- sprintf(
"The REDCapR record export operation was not successful. The error message was:\n%s",
metadata$raw_text
)
stop(error_message)
}
if (!is.null(fields))
fields <- base::union(metadata$plumbing_variables, fields)

record_id_name <- metadata$data$field_name[id_position]
initial_call <- REDCapR::redcap_read_oneshot(
redcap_uri = redcap_uri,
token = token,
records = records,
fields = record_id_name,
fields = metadata$record_id_name,
# forms = forms,
events = events,
filter_logic = filter_logic,
Expand Down

0 comments on commit 91dc988

Please sign in to comment.