-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into add_erase_move_project_field_log_records
- Loading branch information
Showing
93 changed files
with
2,189 additions
and
295 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
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 |
---|---|---|
|
@@ -10,6 +10,11 @@ | |
*.zip | ||
site | ||
!inst/testdata/*.csv | ||
report/*.html | ||
report/*.pdf | ||
report/*.txt | ||
|
||
|
||
|
||
# env file | ||
*.env | ||
|
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: redcapcustodian | ||
Type: Package | ||
Title: Data automation for R-centric workflows with a nod towards REDCap | ||
Version: 1.14.1 | ||
Version: 1.26.2 | ||
Authors@R: c( | ||
person("Philip", "Chase", | ||
email = "[email protected]", | ||
|
@@ -23,6 +23,10 @@ Authors@R: c( | |
email = "[email protected]", | ||
role = "aut", | ||
comment=c(ORCID = "0000-0002-5790-4268")), | ||
person("Sai Pavan", "Kamma", | ||
email = "[email protected]", | ||
role = "aut", | ||
comment=c(ORCID = "0009-0004-4619-0409")), | ||
person("Christopher", "Barnes", | ||
email = "[email protected]", | ||
role = "ctb", | ||
|
@@ -55,17 +59,22 @@ Imports: | |
tibble, | ||
tidyr, | ||
vctrs, | ||
jsonlite | ||
jsonlite, | ||
openxlsx, | ||
quarto | ||
Suggests: | ||
RSQLite, | ||
digest, | ||
dotenv, | ||
duckdb, | ||
fs, | ||
kableExtra, | ||
knitr (>= 1.18), | ||
rmarkdown (>= 2.0), | ||
testthat (>= 3.0.0) | ||
testthat (>= 3.0.0), | ||
tidyverse | ||
VignetteBuilder: knitr | ||
Config/testthat/edition: 3 | ||
RoxygenNote: 7.2.1 | ||
RoxygenNote: 7.3.2 | ||
Depends: | ||
R (>= 2.10) | ||
R (>= 3.5.0) |
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
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,72 @@ | ||
#' Create a REDCap data dictionary from a dataframe | ||
#' | ||
#' @param df the dataframe to generate the data dictionary for | ||
#' @param form_name the form name to display in REDCap | ||
#' @param record_id_col a column in the dataframe that uniquely identifies each record | ||
#' | ||
#' @return A redcap data dictionary | ||
#' @export | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' | ||
#' df <- data.frame( | ||
#' pk_col = c("a1", "a2", "a3"), | ||
#' integer_col = c(1, 2, 3), | ||
#' numeric_col = 5.9, | ||
#' character_col = c("a", "b", "c"), | ||
#' date_col = as.Date("2011-03-07"), | ||
#' date_time_col = as.POSIXct(strptime("2011-03-27 01:30:00", "%Y-%m-%d %H:%M:%S")), | ||
#' email_col = c("[email protected]", "[email protected]", "[email protected]") | ||
#' ) | ||
#' | ||
#' redcap_data_dictionary <- dataframe_to_redcap_dictionary(df, "test_form") | ||
#' redcap_data_dictionary <- dataframe_to_redcap_dictionary(df, "test_form", "character_col") | ||
#' } | ||
dataframe_to_redcap_dictionary <- function(df, | ||
form_name, | ||
record_id_col = NULL) { | ||
contains_emails <- function(col) { | ||
email_pattern <- "^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}$" | ||
return(any(grepl(email_pattern, col))) | ||
} | ||
|
||
get_validation_type <- function(col) { | ||
if (contains_emails(col)) { | ||
return("email") | ||
} | ||
|
||
col_type <- class(col)[1] | ||
switch( | ||
col_type, | ||
"numeric" = "number", | ||
"integer" = "number", | ||
"Date" = "datetime_ymd", | ||
"POSIXct" = "datetime_seconds_ymd", | ||
as.character(NA) | ||
) | ||
} | ||
|
||
# Rearrange the dataframe if a record_id_col is provided | ||
if (!is.null(record_id_col)) { | ||
ordered_df <- df |> | ||
dplyr::select(record_id_col, dplyr::everything()) | ||
} else { | ||
ordered_df <- df | ||
} | ||
|
||
redcap_data_dictionary <- data.frame( | ||
field_name = names(ordered_df), | ||
form_name = form_name, | ||
section_header = as.character(NA), | ||
field_type = "text", | ||
field_label = names(ordered_df), | ||
select_choices_or_calculations = as.character(NA), | ||
field_note = as.character(NA), | ||
text_validation_type_or_show_slider_number = sapply(ordered_df, get_validation_type) | ||
) | ||
|
||
rownames(redcap_data_dictionary) <- NULL | ||
|
||
return(redcap_data_dictionary) | ||
} |
Oops, something went wrong.