From 4fe8a0d73cc7fd176e7130e3a200894ad0c930dc Mon Sep 17 00:00:00 2001 From: agdamsbo <43278243+agdamsbo@users.noreply.github.com> Date: Thu, 28 Nov 2024 13:44:19 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20agdamsbo?= =?UTF-8?q?/REDCapCAST@30d82e528805086bbce7a66fb8286065c3420fde=20?= =?UTF-8?q?=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- articles/REDCapCAST.html | 831 ++++++++++++++++++++++++---- articles/Shiny-app.html | 112 ++-- pkgdown.yml | 2 +- reference/REDCap_split.html | 11 +- reference/as_factor.html | 14 +- reference/easy_redcap.html | 11 +- reference/fct2num.html | 23 +- reference/format_redcap_factor.html | 100 ++++ reference/get_api_key.html | 16 +- reference/index.html | 14 +- reference/is.labelled.html | 5 +- reference/named_levels.html | 26 +- reference/possibly_numeric.html | 93 ++++ reference/read_redcap_tables.html | 50 +- reference/redcap_wider.html | 43 +- reference/sanitize_split.html | 13 +- reference/var2fct.html | 6 +- search.json | 2 +- sitemap.xml | 2 + 19 files changed, 1123 insertions(+), 251 deletions(-) create mode 100644 reference/format_redcap_factor.html create mode 100644 reference/possibly_numeric.html diff --git a/articles/REDCapCAST.html b/articles/REDCapCAST.html index 7a4e25e..8afd43c 100644 --- a/articles/REDCapCAST.html +++ b/articles/REDCapCAST.html @@ -74,14 +74,54 @@
 library(REDCapCAST)
-

This vignette covers the included functions and basic -functionality.

-

A dataset and a meta data file are provided with the package for -demonstration of the functions.

+

This vignette covers the basics to get you started with the two basic +features of REDCapCAST:

+ +
+

Casting meta data +

+

The easiest way is to use the shiny_cast(). You can +access a hosted +version here or launch it locally like this:

+
+shiny_cast()
+
+
+

Reading data from REDCap +

+

To get you started, the easiest way possible, you can use the +easy_redcap() function (example below).

+

You will need an API-key for your REDCap server, the uri/URL/address +for the API connection (usually “https://redcap.YOUR-institution.site/api/”).

+

This function includes a few convenience features to ease your +further work.

+

If your project uses repeating instruments possible as a longitudinal +project, you can choose to widen the data. If not, the result will be a +list of each instrument you have chosen to extract data from. Make sure +to specify only the fields or instruments you need, and avoid to save +any of the data locally, but always source from REDCap to avoid possibly +insecure local storage of sensitive data.

+
+easy_redcap(uri = "YOUR URI", 
+            project.name = "MY_PROJECT", 
+            widen.data = TRUE,
+            fields = c("record_id", "OTHER FIELDS"))
+

Splitting the dataset

-
+

The easy_redcap() function does a few things under the +hood. Below are a few examples to show how the nicely formatted output +is achieved.

+

A sample dataset and Data Dictionary/metadata is provided for this +demonstration:

+
 redcapcast_data |> gt::gt()
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Characteristic +N = 61 +
Legal sex
    female3 (50%)
    male3 (50%)
Hypertension
    No2 (40%)
    Yes3 (60%)
    Unknown1
Diabetes
    No2 (40%)
    Yes3 (60%)
    Unknown1
+1 n (%) +
+
diff --git a/articles/Shiny-app.html b/articles/Shiny-app.html index aa4e366..888b7d0 100644 --- a/articles/Shiny-app.html +++ b/articles/Shiny-app.html @@ -91,68 +91,65 @@ and launch the app as follows:

redcap_wider() #> Joining with `by = join_by(record_id)` #> Joining with `by = join_by(record_id)` -#> Joining with `by = join_by(record_id)` str(ds) -#> 'data.frame': 6 obs. of 52 variables: -#> $ record_id : num 1 2 3 4 5 6 -#> $ cpr : chr "1203401OB4" "0102342303" "2301569823" "0204051342" ... -#> $ inclusion : Date, format: "2023-03-13" "2023-03-01" ... -#> $ inclusion_time : 'hms' num 12:38:49 10:38:57 12:01:07 20:39:19 ... +#> tibble [6 × 49] (S3: tbl_df/tbl/data.frame) +#> $ record_id : num [1:6] 1 2 3 4 5 6 +#> $ cpr : chr [1:6] "1203401OB4" "0102342303" "2301569823" "0204051342" ... +#> $ inclusion : Date[1:6], format: "2023-03-13" "2023-03-01" ... +#> $ inclusion_time : 'hms' num [1:6] 12:38:49 10:38:57 12:01:07 20:39:19 ... #> ..- attr(*, "units")= chr "secs" -#> $ dob : Date, format: "1940-03-12" "1934-02-01" ... -#> $ age : num 83 89.1 66.1 117.9 126.2 ... -#> $ age_integer : num 83 89 66 117 126 91 -#> $ sex : chr "female" "male" "male" "female" ... -#> $ cohabitation : chr "Yes" "Yes" "No" NA ... -#> $ hypertension : chr "No" "No" "Yes" NA ... -#> $ diabetes : chr "Yes" "No" "Yes" NA ... -#> $ region : chr "East" "South" "North" NA ... -#> $ baseline_data_start_complete: chr "Incomplete" "Incomplete" "Incomplete" "Incomplete" ... -#> $ mrs_assessed_inclusion : chr "Yes" "Yes" NA NA ... -#> $ mrs_assessed_follow1 : chr NA "Yes" "Yes" NA ... -#> $ mrs_assessed_follow2 : chr NA NA "Yes" NA ... -#> $ mrs_date_inclusion : Date, format: "2023-03-13" "2023-03-07" ... -#> $ mrs_date_follow1 : Date, format: NA "2023-03-09" ... -#> $ mrs_date_follow2 : Date, format: NA NA ... -#> $ mrs_score_inclusion : num 1 1 NA NA NA NA -#> $ mrs_score_follow1 : num NA 3 2 NA NA NA -#> $ mrs_score_follow2 : num NA NA 1 NA NA NA -#> $ mrs_complete_inclusion : chr "Incomplete" "Incomplete" NA NA ... -#> $ mrs_complete_follow1 : chr NA "Incomplete" "Incomplete" NA ... -#> $ mrs_complete_follow2 : chr NA NA "Incomplete" NA ... -#> $ con_mrs : logi NA NA NA NA NA NA -#> $ con_calc : logi NA NA NA NA NA NA -#> $ consensus_complete : chr NA NA NA NA ... -#> $ event_datetime_1_follow1 : POSIXct, format: NA "2024-01-18 12:49:42" ... -#> $ event_datetime_1_follow2 : POSIXct, format: NA NA ... -#> $ event_age_1_follow1 : num NA NA NA 96 127 NA -#> $ event_age_1_follow2 : num NA NA NA 118 NA NA -#> $ event_type_1_follow1 : chr NA "TIA" "AIS" "TIA" ... -#> $ event_type_1_follow2 : chr NA NA "ICH" "AIS" ... -#> $ new_event_complete_1_follow1: chr NA "Incomplete" "Incomplete" "Complete" ... -#> $ new_event_complete_1_follow2: chr NA NA "Incomplete" "Complete" ... -#> $ event_datetime_2_follow1 : POSIXct, format: NA NA ... -#> $ event_datetime_2_follow2 : POSIXct, format: NA NA ... -#> $ event_datetime_3_follow1 : POSIXct, format: NA NA ... -#> $ event_datetime_3_follow2 : POSIXct, format: NA NA ... -#> $ event_age_2_follow1 : num NA NA NA 105 127 NA -#> $ event_age_2_follow2 : num NA NA NA 118 NA NA -#> $ event_age_3_follow1 : num NA NA NA NA NA NA -#> $ event_age_3_follow2 : num NA NA NA 118 NA NA -#> $ event_type_2_follow1 : chr NA NA "ICH" "TIA" ... -#> $ event_type_2_follow2 : chr NA NA "TIA" "ICH" ... -#> $ event_type_3_follow1 : chr NA NA NA NA ... -#> $ event_type_3_follow2 : chr NA NA "AIS" "Unknown" ... -#> $ new_event_complete_2_follow1: chr NA NA "Incomplete" "Complete" ... -#> $ new_event_complete_2_follow2: chr NA NA "Incomplete" "Incomplete" ... -#> $ new_event_complete_3_follow1: chr NA NA NA NA ... -#> $ new_event_complete_3_follow2: chr NA NA "Incomplete" "Complete" ...
+#> $ dob : Date[1:6], format: "1940-03-12" "1934-02-01" ... +#> $ age : num [1:6] 83 89.1 66.1 117.9 126.2 ... +#> $ age_integer : num [1:6] 83 89 66 117 126 91 +#> $ sex : chr [1:6] "female" "male" "male" "female" ... +#> $ cohabitation : chr [1:6] "Yes" "Yes" "No" NA ... +#> $ hypertension : chr [1:6] "No" "No" "Yes" NA ... +#> $ diabetes : chr [1:6] "Yes" "No" "Yes" NA ... +#> $ region : chr [1:6] "East" "South" "North" NA ... +#> $ baseline_data_start_complete: chr [1:6] "Incomplete" "Incomplete" "Incomplete" "Incomplete" ... +#> $ mrs_assessed_inclusion : chr [1:6] "Yes" "Yes" NA NA ... +#> $ mrs_assessed_follow1 : chr [1:6] NA "Yes" "Yes" NA ... +#> $ mrs_assessed_follow2 : chr [1:6] NA NA "Yes" NA ... +#> $ mrs_date_inclusion : Date[1:6], format: "2023-03-13" "2023-03-07" ... +#> $ mrs_date_follow1 : Date[1:6], format: NA "2023-03-09" ... +#> $ mrs_date_follow2 : Date[1:6], format: NA NA ... +#> $ mrs_score_inclusion : num [1:6] 1 1 NA NA NA NA +#> $ mrs_score_follow1 : num [1:6] NA 3 2 NA NA NA +#> $ mrs_score_follow2 : num [1:6] NA NA 1 NA NA NA +#> $ mrs_complete_inclusion : chr [1:6] "Incomplete" "Incomplete" NA NA ... +#> $ mrs_complete_follow1 : chr [1:6] NA "Incomplete" "Incomplete" NA ... +#> $ mrs_complete_follow2 : chr [1:6] NA NA "Incomplete" NA ... +#> $ event_datetime_1_follow1 : POSIXct[1:6], format: NA "2024-01-18 12:49:42" ... +#> $ event_datetime_1_follow2 : POSIXct[1:6], format: NA NA ... +#> $ event_age_1_follow1 : num [1:6] NA NA NA 96 127 NA +#> $ event_age_1_follow2 : num [1:6] NA NA NA 118 NA NA +#> $ event_type_1_follow1 : chr [1:6] NA "TIA" "AIS" "TIA" ... +#> $ event_type_1_follow2 : chr [1:6] NA NA "ICH" "AIS" ... +#> $ new_event_complete_1_follow1: chr [1:6] NA "Incomplete" "Incomplete" "Complete" ... +#> $ new_event_complete_1_follow2: chr [1:6] NA NA "Incomplete" "Complete" ... +#> $ event_datetime_2_follow1 : POSIXct[1:6], format: NA NA ... +#> $ event_datetime_2_follow2 : POSIXct[1:6], format: NA NA ... +#> $ event_datetime_3_follow1 : POSIXct[1:6], format: NA NA ... +#> $ event_datetime_3_follow2 : POSIXct[1:6], format: NA NA ... +#> $ event_age_2_follow1 : num [1:6] NA NA NA 105 127 NA +#> $ event_age_2_follow2 : num [1:6] NA NA NA 118 NA NA +#> $ event_age_3_follow1 : num [1:6] NA NA NA NA NA NA +#> $ event_age_3_follow2 : num [1:6] NA NA NA 118 NA NA +#> $ event_type_2_follow1 : chr [1:6] NA NA "ICH" "TIA" ... +#> $ event_type_2_follow2 : chr [1:6] NA NA "TIA" "ICH" ... +#> $ event_type_3_follow1 : chr [1:6] NA NA NA NA ... +#> $ event_type_3_follow2 : chr [1:6] NA NA "AIS" "Unknown" ... +#> $ new_event_complete_2_follow1: chr [1:6] NA NA "Incomplete" "Complete" ... +#> $ new_event_complete_2_follow2: chr [1:6] NA NA "Incomplete" "Incomplete" ... +#> $ new_event_complete_3_follow1: chr [1:6] NA NA NA NA ... +#> $ new_event_complete_3_follow2: chr [1:6] NA NA "Incomplete" "Complete" ... +#> - attr(*, "problems")=<externalptr>
 ds|> 
   ds2dd_detailed(metadata = names(REDCapCAST::redcapcast_meta))|>  
   purrr::pluck("data") |> 
   str()
-#> tibble [6 × 52] (S3: tbl_df/tbl/data.frame)
+#> tibble [6 × 49] (S3: tbl_df/tbl/data.frame)
 #>  $ record_id                   : num [1:6] 1 2 3 4 5 6
 #>  $ cpr                         : chr [1:6] "1203401OB4" "0102342303" "2301569823" "0204051342" ...
 #>  $ inclusion                   : Date[1:6], format: "2023-03-13" "2023-03-01" ...
@@ -178,9 +175,6 @@ and launch the app as follows:

#> $ mrs_complete_inclusion : chr [1:6] "Incomplete" "Incomplete" NA NA ... #> $ mrs_complete_follow1 : chr [1:6] NA "Incomplete" "Incomplete" NA ... #> $ mrs_complete_follow2 : chr [1:6] NA NA "Incomplete" NA ... -#> $ con_mrs : Factor w/ 2 levels "FALSE","TRUE": NA NA NA NA NA NA -#> $ con_calc : Factor w/ 2 levels "FALSE","TRUE": NA NA NA NA NA NA -#> $ consensus_complete : chr [1:6] NA NA NA NA ... #> $ event_datetime_1_follow1 : POSIXct[1:6], format: NA "2024-01-18 12:49:42" ... #> $ event_datetime_1_follow2 : POSIXct[1:6], format: NA NA ... #> $ event_age_1_follow1 : num [1:6] NA NA NA 96 127 NA @@ -223,7 +217,7 @@ and launch the app as follows:

#> 8 sex data NA text sex #> 9 cohabitation data NA text cohabitation #> 10 hypertension data NA text hypertension -#> # ℹ 13 more variables: select_choices_or_calculations <chr>, field_note <lgl>, +#> # ℹ 13 more variables: select_choices_or_calculations <lgl>, field_note <lgl>, #> # text_validation_type_or_show_slider_number <chr>, #> # text_validation_min <lgl>, text_validation_max <lgl>, identifier <lgl>, #> # branching_logic <lgl>, required_field <lgl>, custom_alignment <lgl>, diff --git a/pkgdown.yml b/pkgdown.yml index 74bf059..ceb0c75 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -5,7 +5,7 @@ articles: Database-creation: Database-creation.html REDCapCAST: REDCapCAST.html Shiny-app: Shiny-app.html -last_built: 2024-11-27T15:00Z +last_built: 2024-11-28T13:43Z urls: reference: https://agdamsbo.github.io/REDCapCAST/reference article: https://agdamsbo.github.io/REDCapCAST/articles diff --git a/reference/REDCap_split.html b/reference/REDCap_split.html index 62f57e6..84a7755 100644 --- a/reference/REDCap_split.html +++ b/reference/REDCap_split.html @@ -76,8 +76,7 @@ JSON from an API call.

primary_table_name

Name given to the list element for the primary -output table (as described in README.md). Ignored if -forms = 'all'.

+output table. Ignored if forms = 'all'.

forms
@@ -95,7 +94,7 @@ instruments only or for all forms.

Author

-

Paul W. Egeler, M.S., GStat

+

Paul W. Egeler

@@ -123,7 +122,7 @@ instruments only or for all forms.

) # Convert exported JSON strings into a list of data.frames -REDCapRITS::REDCap_split(records, metadata) +REDCapCAST::REDCap_split(records, metadata) # Using a raw data export ------------------------------------------------- @@ -136,7 +135,7 @@ instruments only or for all forms.

) # Split the tables -REDCapRITS::REDCap_split(records, metadata) +REDCapCAST::REDCap_split(records, metadata) # In conjunction with the R export script --------------------------------- @@ -153,7 +152,7 @@ instruments only or for all forms.

metadata <- read.csv("ExampleProject_DataDictionary_2018-06-03.csv") # Split the tables -REDCapRITS::REDCap_split(data, metadata) +REDCapCAST::REDCap_split(data, metadata) setwd(old) } # }
diff --git a/reference/as_factor.html b/reference/as_factor.html index 927e247..042c559 100644 --- a/reference/as_factor.html +++ b/reference/as_factor.html @@ -1,7 +1,7 @@ -Convert labelled vectors to factors while preserving attributes — as_factor • REDCapCAST Skip to contents @@ -43,7 +43,7 @@ ta loss in case of rich formatted and labelled data.'>
-

This extends [forcats::as_factor()] as well as [haven::as_factor()], by appending +

This extends as_factor as well as as_factor, by appending original attributes except for "class" after converting to factor to avoid ta loss in case of rich formatted and labelled data.

@@ -80,14 +80,6 @@ ta loss in case of rich formatted and labelled data.

... ) -# S3 method for class 'redcapcast_labelled' -as_factor( - x, - levels = c("default", "labels", "values", "both"), - ordered = FALSE, - ... -) - # S3 method for class 'data.frame' as_factor(x, ..., only_labelled = TRUE) diff --git a/reference/easy_redcap.html b/reference/easy_redcap.html index 7f39c74..263e32a 100644 --- a/reference/easy_redcap.html +++ b/reference/easy_redcap.html @@ -53,7 +53,7 @@
project.name

The name of the current project (for key storage with -`keyring::key_set()`, using the default keyring)

+key_set, using the default keyring)

widen.data
@@ -65,7 +65,7 @@
...
-

arguments passed on to `REDCapCAST::read_redcap_tables()`

+

arguments passed on to read_redcap_tables.

@@ -73,6 +73,13 @@

data.frame or list depending on widen.data

+
+

Examples

+
if (FALSE) { # \dontrun{
+easy_redcap("My_new_project",fields=c("record_id","age","hypertension"))
+} # }
+
+
diff --git a/reference/fct2num.html b/reference/fct2num.html index 8520730..6e37557 100644 --- a/reference/fct2num.html +++ b/reference/fct2num.html @@ -83,23 +83,12 @@ fct2num() #> [1] 1 2 3 2 10 9 -# Outlier with labels, but no class of origin, handled like numeric vector -# structure(c(1, 2, 3, 2, 10, 9), -# labels = c(Unknown = 9, Refused = 10) -# ) |> -# as_factor() |> -# fct2num() - -v <- sample(6:19, 20, TRUE) |> factor() -dput(v) -#> structure(c(7L, 1L, 10L, 3L, 10L, 10L, 9L, 8L, 3L, 2L, 6L, 8L, -#> 3L, 5L, 4L, 8L, 1L, 6L, 5L, 5L), levels = c("6", "7", "8", "9", -#> "11", "12", "13", "15", "16", "17"), class = "factor") -named_levels(v) -#> 13 6 17 8 16 15 7 12 11 9 -#> 7 1 10 3 9 8 2 6 5 4 -fct2num(v) -#> [1] 13 6 17 8 17 17 16 15 8 7 12 15 8 11 9 15 6 12 11 11 +structure(c(1, 2, 3, 2, 10, 9), + labels = c(Unknown = 9, Refused = 10) +) |> + as_factor() |> + fct2num() +#> [1] 1 2 3 2 NA NA