-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
532 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: redcapfiller | ||
Type: Package | ||
Title: Fill a REDCap Project with Generated Data | ||
Version: 0.1.0 | ||
Version: 0.1.0.9001 | ||
Authors@R: c( | ||
person("Philip", "Chase", | ||
email = "[email protected]", | ||
|
@@ -37,6 +37,8 @@ Suggests: | |
Config/testthat/edition: 3 | ||
Imports: | ||
dplyr, | ||
lorem, | ||
purrr, | ||
rlang, | ||
tidyr | ||
RoxygenNote: 7.3.2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# redcapfiller (0.1.0.9001) | ||
|
||
* Supports filling of checkbox, dropdown, radio, yes/no, True/False and unvalidated text fields on classic projects. | ||
* Provides a proof_of_concept.R script with write-back to a demonstration project and properly managed secrets. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#' @title generate text field values | ||
#' @description | ||
#' Provide a set of values for each field in the output of | ||
#' `get_long_text_fields` | ||
#' | ||
#' @param long_text_fields a long data set of text | ||
#' fields, their parameters, and weights. | ||
#' | ||
#' @return a long dataframe of text field values with one row for each value set. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' get_long_text_field_values(long_text_fields) | ||
#' } | ||
get_long_text_field_values <- function(long_text_fields) { | ||
tvt_na <- function(df) { | ||
df |> | ||
dplyr::filter(.data$tvt == "tvt_na") |> | ||
dplyr::mutate(value = replicate(length(.data$field_name), lorem::ipsum_words(round(stats::rnorm(mean = .data$mean, sd = .data$sd, n = 1))))) | ||
# |> | ||
# dplyr::slice_sample(prop = 0.5, weight_by = .data$weight) | ||
} | ||
|
||
tvt_types <- c( | ||
"tvt_na" | ||
) | ||
|
||
process_one_text_validation_type <- function(my_tvt, df) { | ||
# exec (run) the function named in `alert` on the rows of data that | ||
# have an alert_type of `alert` | ||
result <- rlang::exec(my_tvt, df |> | ||
dplyr::filter(.data$tvt == my_tvt)) | ||
return(result) | ||
} | ||
|
||
text_field_values <- | ||
purrr::map(tvt_types, | ||
process_one_text_validation_type, | ||
long_text_fields |> dplyr::filter(.data$field_type == "text") | ||
) |> | ||
dplyr::bind_rows() | ||
|
||
result <- text_field_values |> | ||
dplyr::select("field_name", "value") | ||
|
||
return(result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#' @title Get every text field response from a REDCap data dictionary | ||
#' | ||
#' @description | ||
#' Given a REDCap data dictionary, enumerate every text field in that data dictionary and return a dataset with default weights | ||
#' | ||
#' @param metadata A REDCap data dictionary | ||
#' | ||
#' @returns a dataframe with these columns | ||
#' \describe{ | ||
#' \item{field_name}{REDCap field name} | ||
#' \item{form_name}{REDCap form name} | ||
#' \item{field_type}{REDCap field type} | ||
#' \item{text_validation_type}{REDCap text validation type} | ||
#' \item{text_validation_min}{REDCap text validation min} | ||
#' \item{text_validation_max}{REDCap text validation max} | ||
#' \item{tvt}{text validation type function name} | ||
#' \item{weight}{a default weight for the field} | ||
#' \item{mean}{mean of data to be generated} | ||
#' \item{sd}{standard deviation of data to be generated} | ||
#' } | ||
#' @export | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' long_text_fields <- | ||
#' get_long_text_fields(metadata_to_populate) | ||
#' } | ||
get_long_text_fields <- function(metadata) { | ||
text_fields <- | ||
metadata |> | ||
# include only categorical field types | ||
dplyr::filter(.data$field_type %in% c("text")) |> | ||
# excluding anything displayed by branching logic | ||
dplyr::filter(is.na(.data$branching_logic)) |> | ||
# narrow our focus to the required columns | ||
dplyr::select(c( | ||
"field_name", | ||
"form_name", | ||
"field_type", | ||
"text_validation_type_or_show_slider_number", | ||
"text_validation_min", | ||
"text_validation_max" | ||
)) |> | ||
dplyr::rename(text_validation_type = "text_validation_type_or_show_slider_number") |> | ||
dplyr::mutate(tvt = dplyr::case_when( | ||
is.na(.data$text_validation_type) ~ "tvt_na", | ||
TRUE ~ "tvt_unsupported" | ||
)) |> | ||
# set weights for each response | ||
dplyr::mutate(weight = 100) | ||
|
||
tvt_na <- function(text_fields) { | ||
result <- | ||
text_fields |> | ||
dplyr::filter(is.na(.data$text_validation_type)) |> | ||
dplyr::mutate(mean = 1.5, sd = 0.8) | ||
return(result) | ||
} | ||
|
||
tvt_unsupported <- function(text_fields) { | ||
result <- | ||
text_fields |> | ||
dplyr::filter(F) | ||
return(result) | ||
} | ||
|
||
tvt_types <- c( | ||
"tvt_na", | ||
"tvt_unsupported" | ||
) | ||
|
||
process_one_text_validation_type <- function(my_tvt, df) { | ||
# exec (run) the function named in `alert` on the rows of data that | ||
# have an alert_type of `alert` | ||
result <- rlang::exec(my_tvt, df |> | ||
dplyr::filter(.data$tvt == my_tvt)) | ||
return(result) | ||
} | ||
|
||
text_fields_and_weights <- | ||
purrr::map(tvt_types, process_one_text_validation_type, text_fields) |> | ||
dplyr::bind_rows() | ||
|
||
return(text_fields_and_weights) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
filler_demo_pid=15321 | ||
path_credential = ~/credentials.csv | ||
path_credential=~/credentials.csv |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.