Stepwise removal on non-alphanumeric characters, trailing white space, +substitutes spaces for underscores and converts to lower case. +Trying to make up for different naming conventions.
+diff --git a/NAMESPACE b/NAMESPACE index 1137ebc..6ea6314 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand export(REDCap_split) +export(clean_redcap_name) export(focused_metadata) export(match_fields_to_form) export(read_redcap_tables) diff --git a/R/sysdata.rda b/R/sysdata.rda index 0299f29..cb869c8 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/data-raw/redcapcast_meta.R b/data-raw/redcapcast_meta.R index fe9f3f6..23a7dba 100644 --- a/data-raw/redcapcast_meta.R +++ b/data-raw/redcapcast_meta.R @@ -1,5 +1,5 @@ ## code to prepare `redcapcast_meta` dataset goes here -redcapcast_meta <- REDCapR::redcap_metadata_read(redcap_uri = uri, +redcapcast_meta <- REDCapR::redcap_metadata_read(redcap_uri = keyring::key_get("DB_URI"), token = keyring::key_get("cast_api") )$data diff --git a/data/redcapcast_meta.rda b/data/redcapcast_meta.rda index 35cce09..36c58c9 100644 Binary files a/data/redcapcast_meta.rda and b/data/redcapcast_meta.rda differ diff --git a/docs/articles/Introduction.html b/docs/articles/Introduction.html index 881bd31..c4dd0ef 100644 --- a/docs/articles/Introduction.html +++ b/docs/articles/Introduction.html @@ -91,12 +91,12 @@ demonstration of the functions.
redcapcast_data |> gt::gt()
redcapcast_meta |> gt::gt()
list <-
- REDCapCAST::REDCap_split(records = redcapcast_data,
+ REDCap_split(records = redcapcast_data,
metadata = redcapcast_meta,
forms = "repeating")
str(list)
#> List of 2
-#> $ :'data.frame': 9 obs. of 20 variables:
-#> ..$ record_id : num [1:9] 1 2 2 3 3 3 4 4 5
-#> ..$ redcap_event_name: chr [1:9] "inclusion" "inclusion" "follow1" "inclusion" ...
-#> ..$ cpr : chr [1:9] "1203401OB4" "0102342303" NA "2301569823" ...
-#> ..$ inclusion : Date[1:9], format: "2023-03-13" "2023-03-01" ...
-#> ..$ dob : Date[1:9], format: "1940-03-12" "1934-02-01" ...
-#> ..$ age : num [1:9] 83 89.1 NA 66.1 NA ...
-#> ..$ age_integer : num [1:9] 83 89 NA 66 NA NA 117 NA 126
-#> ..$ sex : chr [1:9] "female" "male" NA "male" ...
-#> ..$ cohabitation : chr [1:9] "Yes" "Yes" NA "No" ...
-#> ..$ hypertension : chr [1:9] "No" "No" NA "Yes" ...
-#> ..$ diabetes : chr [1:9] "Yes" "No" NA "Yes" ...
-#> ..$ region : chr [1:9] "East" "South" NA "North" ...
-#> ..$ base_complete : chr [1:9] "Incomplete" "Incomplete" NA "Incomplete" ...
-#> ..$ mrs_assessed : chr [1:9] "Yes" "Yes" "Yes" NA ...
-#> ..$ mrs_date : Date[1:9], format: "2023-03-13" "2023-03-07" ...
-#> ..$ mrs_score : num [1:9] 1 1 3 NA 2 1 NA NA NA
-#> ..$ mrs_complete : chr [1:9] "Incomplete" "Incomplete" "Incomplete" "Incomplete" ...
-#> ..$ event_date : Date[1:9], format: NA NA ...
-#> ..$ event_type : chr [1:9] NA NA NA NA ...
-#> ..$ event_complete : chr [1:9] NA NA NA NA ...
-#> $ Event:'data.frame': 9 obs. of 4 variables:
+#> $ :'data.frame': 9 obs. of 17 variables:
+#> ..$ record_id : num [1:9] 1 2 2 3 3 3 4 4 5
+#> ..$ redcap_event_name : chr [1:9] "inclusion" "inclusion" "follow1" "inclusion" ...
+#> ..$ cpr : chr [1:9] "1203401OB4" "0102342303" NA "2301569823" ...
+#> ..$ inclusion : Date[1:9], format: "2023-03-13" "2023-03-01" ...
+#> ..$ dob : Date[1:9], format: "1940-03-12" "1934-02-01" ...
+#> ..$ age : num [1:9] 83 89.1 NA 66.1 NA ...
+#> ..$ age_integer : num [1:9] 83 89 NA 66 NA NA 117 NA 126
+#> ..$ sex : chr [1:9] "female" "male" NA "male" ...
+#> ..$ cohabitation : chr [1:9] "Yes" "Yes" NA "No" ...
+#> ..$ hypertension : chr [1:9] "No" "No" NA "Yes" ...
+#> ..$ diabetes : chr [1:9] "Yes" "No" NA "Yes" ...
+#> ..$ region : chr [1:9] "East" "South" NA "North" ...
+#> ..$ baseline_data_start_complete: chr [1:9] "Incomplete" "Incomplete" NA "Incomplete" ...
+#> ..$ mrs_assessed : chr [1:9] "Yes" "Yes" "Yes" NA ...
+#> ..$ mrs_date : Date[1:9], format: "2023-03-13" "2023-03-07" ...
+#> ..$ mrs_score : num [1:9] 1 1 3 NA 2 1 NA NA NA
+#> ..$ mrs_complete : chr [1:9] "Incomplete" "Incomplete" "Incomplete" "Incomplete" ...
+#> $ new_event:'data.frame': 9 obs. of 7 variables:
#> ..$ record_id : num [1:9] 2 3 3 3 3 3 4 4 4
#> ..$ redcap_event_name : chr [1:9] "follow1" "follow1" "follow1" "follow2" ...
-#> ..$ redcap_repeat_instrument: chr [1:9] "Event" "Event" "Event" "Event" ...
-#> ..$ redcap_repeat_instance : num [1:9] 1 1 2 1 2 3 1 2 3
list <-
- REDCapCAST::REDCap_split(records = redcapcast_data,
+ REDCap_split(records = redcapcast_data,
metadata = redcapcast_meta,
forms = "all")
str(list)
-#> List of 4
-#> $ base :'data.frame': 9 obs. of 13 variables:
-#> ..$ record_id : num [1:9] 1 2 2 3 3 3 4 4 5
-#> ..$ redcap_event_name: chr [1:9] "inclusion" "inclusion" "follow1" "inclusion" ...
-#> ..$ cpr : chr [1:9] "1203401OB4" "0102342303" NA "2301569823" ...
-#> ..$ inclusion : Date[1:9], format: "2023-03-13" "2023-03-01" ...
-#> ..$ dob : Date[1:9], format: "1940-03-12" "1934-02-01" ...
-#> ..$ age : num [1:9] 83 89.1 NA 66.1 NA ...
-#> ..$ age_integer : num [1:9] 83 89 NA 66 NA NA 117 NA 126
-#> ..$ sex : chr [1:9] "female" "male" NA "male" ...
-#> ..$ cohabitation : chr [1:9] "Yes" "Yes" NA "No" ...
-#> ..$ hypertension : chr [1:9] "No" "No" NA "Yes" ...
-#> ..$ diabetes : chr [1:9] "Yes" "No" NA "Yes" ...
-#> ..$ region : chr [1:9] "East" "South" NA "North" ...
-#> ..$ base_complete : chr [1:9] "Incomplete" "Incomplete" NA "Incomplete" ...
-#> $ mrs :'data.frame': 9 obs. of 6 variables:
+#> List of 3
+#> $ baseline_data_start:'data.frame': 9 obs. of 13 variables:
+#> ..$ record_id : num [1:9] 1 2 2 3 3 3 4 4 5
+#> ..$ redcap_event_name : chr [1:9] "inclusion" "inclusion" "follow1" "inclusion" ...
+#> ..$ cpr : chr [1:9] "1203401OB4" "0102342303" NA "2301569823" ...
+#> ..$ inclusion : Date[1:9], format: "2023-03-13" "2023-03-01" ...
+#> ..$ dob : Date[1:9], format: "1940-03-12" "1934-02-01" ...
+#> ..$ age : num [1:9] 83 89.1 NA 66.1 NA ...
+#> ..$ age_integer : num [1:9] 83 89 NA 66 NA NA 117 NA 126
+#> ..$ sex : chr [1:9] "female" "male" NA "male" ...
+#> ..$ cohabitation : chr [1:9] "Yes" "Yes" NA "No" ...
+#> ..$ hypertension : chr [1:9] "No" "No" NA "Yes" ...
+#> ..$ diabetes : chr [1:9] "Yes" "No" NA "Yes" ...
+#> ..$ region : chr [1:9] "East" "South" NA "North" ...
+#> ..$ baseline_data_start_complete: chr [1:9] "Incomplete" "Incomplete" NA "Incomplete" ...
+#> $ mrs :'data.frame': 9 obs. of 6 variables:
#> ..$ record_id : num [1:9] 1 2 2 3 3 3 4 4 5
#> ..$ redcap_event_name: chr [1:9] "inclusion" "inclusion" "follow1" "inclusion" ...
#> ..$ mrs_assessed : chr [1:9] "Yes" "Yes" "Yes" NA ...
#> ..$ mrs_date : Date[1:9], format: "2023-03-13" "2023-03-07" ...
#> ..$ mrs_score : num [1:9] 1 1 3 NA 2 1 NA NA NA
#> ..$ mrs_complete : chr [1:9] "Incomplete" "Incomplete" "Incomplete" "Incomplete" ...
-#> $ event:'data.frame': 9 obs. of 5 variables:
-#> ..$ record_id : num [1:9] 1 2 2 3 3 3 4 4 5
-#> ..$ redcap_event_name: chr [1:9] "inclusion" "inclusion" "follow1" "inclusion" ...
-#> ..$ event_date : Date[1:9], format: NA NA ...
-#> ..$ event_type : chr [1:9] NA NA NA NA ...
-#> ..$ event_complete : chr [1:9] NA NA NA NA ...
-#> $ Event:'data.frame': 9 obs. of 4 variables:
+#> $ new_event :'data.frame': 9 obs. of 7 variables:
#> ..$ record_id : num [1:9] 2 3 3 3 3 3 4 4 4
#> ..$ redcap_event_name : chr [1:9] "follow1" "follow1" "follow1" "follow2" ...
-#> ..$ redcap_repeat_instrument: chr [1:9] "Event" "Event" "Event" "Event" ...
-#> ..$ redcap_repeat_instance : num [1:9] 1 1 2 1 2 3 1 2 3
This function wraps all the above demonstrated function to get the
dataset, the metadata, apply the REDCap_split
function and
-then a bit of cleaning.
The function works very similar to the
-REDCapR::redcap_read()
.
REDCapR::redcap_read()
in allowing to specify fields,
+events and forms for export instead of exporting the whole database and
+filtering afterwards. I believe this is a better and safer, focused
+approach.
-# read_redcap_tables(uri = "YOUR URI", token = "YOUR TOKEN")
-
-# ds <- read_redcap_tables(uri = key_get("DB_URI"), token = key_get("cast_api"))
# read_redcap_tables(uri = "YOUR URI", token = "YOUR TOKEN")
Stepwise removal on non-alphanumeric characters, trailing white space, +substitutes spaces for underscores and converts to lower case. +Trying to make up for different naming conventions.
+clean_redcap_name()
+ focused_metadata()
region, character
Completed, character
Event type, character
Completed, character