diff --git a/pkgdown.yml b/pkgdown.yml index 1f28a06..5b1eced 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-20T15:36Z +last_built: 2024-11-21T10:29Z urls: reference: https://agdamsbo.github.io/REDCapCAST/reference article: https://agdamsbo.github.io/REDCapCAST/articles diff --git a/reference/all_na.html b/reference/all_na.html new file mode 100644 index 0000000..4d5e577 --- /dev/null +++ b/reference/all_na.html @@ -0,0 +1,88 @@ + +Check if vector is all NA — all_na • REDCapCAST + Skip to contents + + +
+
+
+ +
+

Check if vector is all NA

+
+ +
+

Usage

+
all_na(data)
+
+ +
+

Arguments

+ + +
data
+

vector of data.frame

+ +
+
+

Value

+

logical

+
+ +
+

Examples

+
rep(NA,4) |> all_na()
+#> [1] TRUE
+
+
+
+ + +
+ + + + + + + diff --git a/reference/compact_vec.html b/reference/compact_vec.html new file mode 100644 index 0000000..fd2015a --- /dev/null +++ b/reference/compact_vec.html @@ -0,0 +1,106 @@ + +Compacting a vector of any length with or without names — compact_vec • REDCapCAST + Skip to contents + + +
+
+
+ +
+

Compacting a vector of any length with or without names

+
+ +
+

Usage

+
compact_vec(data, nm.sep = ": ", val.sep = "; ")
+
+ +
+

Arguments

+ + +
data
+

vector, optionally named

+ + +
nm.sep
+

string separating name from value if any

+ + +
val.sep
+

string separating values

+ +
+
+

Value

+

character string

+
+ +
+

Examples

+
sample(seq_len(4), 20, TRUE) |>
+  as_factor() |>
+  named_levels() |>
+  sort() |>
+  compact_vec()
+#> [1] "1: 1; 2: 2; 3: 3; 4: 4"
+1:6 |> compact_vec()
+#> [1] "1; 2; 3; 4; 5; 6"
+"test" |> compact_vec()
+#> [1] "test"
+sample(letters[1:9], 20, TRUE) |> compact_vec()
+#> [1] "g; e; e; b; f; d; b; c; i; f; g; e; f; i; f; e; b; a; d; h"
+
+
+
+ + +
+ + + + + + + diff --git a/reference/create_instrument_meta.html b/reference/create_instrument_meta.html index 0d718e8..b933e6a 100644 --- a/reference/create_instrument_meta.html +++ b/reference/create_instrument_meta.html @@ -91,7 +91,6 @@ Default is TRUE.

) ) |> purrr::pluck("meta") -#> A default id column has been added # data |> create_instrument_meta() data <- iris |> @@ -103,7 +102,7 @@ Default is TRUE.

ds2dd_detailed(form.sep = "__") #> $data #> # A tibble: 150 × 5 -#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species +#> sepal.length sepal.width petal.length petal.width species #> <dbl> <dbl> <dbl> <dbl> <fct> #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3 1.4 0.2 setosa @@ -121,11 +120,11 @@ Default is TRUE.

#> # A tibble: 5 × 18 #> field_name form_name section_header field_type field_label #> <chr> <chr> <lgl> <chr> <chr> -#> 1 Sepal.Length b NA text Sepal.Length -#> 2 Sepal.Width b NA text Sepal.Width -#> 3 Petal.Length b NA text Petal.Length -#> 4 Petal.Width b NA text Petal.Width -#> 5 Species b NA radio Species +#> 1 sepal.length b NA text Sepal.Length +#> 2 sepal.width b NA text Sepal.Width +#> 3 petal.length b NA text Petal.Length +#> 4 petal.width b NA text Petal.Width +#> 5 species b NA radio Species #> # ℹ 13 more variables: select_choices_or_calculations <chr>, field_note <lgl>, #> # text_validation_type_or_show_slider_number <chr>, #> # text_validation_min <lgl>, text_validation_max <lgl>, identifier <lgl>, diff --git a/reference/ds2dd_detailed.html b/reference/ds2dd_detailed.html index 911e29f..8b3ac17 100644 --- a/reference/ds2dd_detailed.html +++ b/reference/ds2dd_detailed.html @@ -142,24 +142,201 @@ Please, do always inspect the data dictionary before upload.

Examples

-
if (FALSE) { # \dontrun{
-data <- REDCapCAST::redcapcast_data
-data |> ds2dd_detailed()
+    
## Basic parsing with default options
+REDCapCAST::redcapcast_data |>
+  dplyr::select(-dplyr::starts_with("redcap_")) |>
+  ds2dd_detailed()
+#> $data
+#> # A tibble: 25 × 24
+#>    record_id cpr    inclusion  inclusion_time dob          age age_integer sex  
+#>        <dbl> <chr>  <date>     <chr>          <date>     <dbl>       <dbl> <chr>
+#>  1         1 12034… 2023-03-13 12:38:49       1940-03-12  83.0          83 fema…
+#>  2         2 01023… 2023-03-01 10:38:57       1934-02-01  89.1          89 male 
+#>  3         2 NA     NA         NA             NA          NA            NA NA   
+#>  4         2 NA     NA         NA             NA          NA            NA NA   
+#>  5         3 23015… 2022-03-08 12:01:07       1956-01-23  66.1          66 male 
+#>  6         3 NA     NA         NA             NA          NA            NA NA   
+#>  7         3 NA     NA         NA             NA          NA            NA NA   
+#>  8         3 NA     NA         NA             NA          NA            NA NA   
+#>  9         3 NA     NA         NA             NA          NA            NA NA   
+#> 10         3 NA     NA         NA             NA          NA            NA NA   
+#> # ℹ 15 more rows
+#> # ℹ 16 more variables: cohabitation <chr>, hypertension <chr>, diabetes <chr>,
+#> #   region <chr>, baseline_data_start_complete <chr>, mrs_assessed <chr>,
+#> #   mrs_date <date>, mrs_score <dbl>, mrs_complete <chr>, con_mrs <fct>,
+#> #   con_calc <fct>, consensus_complete <chr>, event_datetime <dttm>,
+#> #   event_age <dbl>, event_type <chr>, new_event_complete <chr>
+#> 
+#> $meta
+#> # A tibble: 24 × 18
+#>    field_name     form_name section_header field_type field_label   
+#>    <chr>          <chr>     <lgl>          <chr>      <chr>         
+#>  1 record_id      data      NA             text       record_id     
+#>  2 cpr            data      NA             text       cpr           
+#>  3 inclusion      data      NA             text       inclusion     
+#>  4 inclusion_time data      NA             text       inclusion_time
+#>  5 dob            data      NA             text       dob           
+#>  6 age            data      NA             text       age           
+#>  7 age_integer    data      NA             text       age_integer   
+#>  8 sex            data      NA             text       sex           
+#>  9 cohabitation   data      NA             text       cohabitation  
+#> 10 hypertension   data      NA             text       hypertension  
+#> # ℹ 14 more rows
+#> # ℹ 13 more variables: select_choices_or_calculations <chr>, 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>,
+#> #   question_number <lgl>, matrix_group_name <lgl>, matrix_ranking <lgl>,
+#> #   field_annotation <lgl>
+#> 
+#> attr(,"class")
+#> [1] "REDCapCAST" "list"      
+
+## Adding a record_id field
 iris |> ds2dd_detailed(add.auto.id = TRUE)
+#> $data
+#> # A tibble: 150 × 6
+#>    record_id sepal.length sepal.width petal.length petal.width species
+#>        <int>        <dbl>       <dbl>        <dbl>       <dbl> <fct>  
+#>  1         1          5.1         3.5          1.4         0.2 setosa 
+#>  2         2          4.9         3            1.4         0.2 setosa 
+#>  3         3          4.7         3.2          1.3         0.2 setosa 
+#>  4         4          4.6         3.1          1.5         0.2 setosa 
+#>  5         5          5           3.6          1.4         0.2 setosa 
+#>  6         6          5.4         3.9          1.7         0.4 setosa 
+#>  7         7          4.6         3.4          1.4         0.3 setosa 
+#>  8         8          5           3.4          1.5         0.2 setosa 
+#>  9         9          4.4         2.9          1.4         0.2 setosa 
+#> 10        10          4.9         3.1          1.5         0.1 setosa 
+#> # ℹ 140 more rows
+#> 
+#> $meta
+#> # A tibble: 6 × 18
+#>   field_name   form_name section_header field_type field_label 
+#>   <chr>        <chr>     <lgl>          <chr>      <chr>       
+#> 1 record_id    data      NA             text       record_id   
+#> 2 sepal.length data      NA             text       Sepal.Length
+#> 3 sepal.width  data      NA             text       Sepal.Width 
+#> 4 petal.length data      NA             text       Petal.Length
+#> 5 petal.width  data      NA             text       Petal.Width 
+#> 6 species      data      NA             radio      Species     
+#> # ℹ 13 more variables: select_choices_or_calculations <chr>, 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>,
+#> #   question_number <lgl>, matrix_group_name <lgl>, matrix_ranking <lgl>,
+#> #   field_annotation <lgl>
+#> 
+#> attr(,"class")
+#> [1] "REDCapCAST" "list"      
+
+## Passing form name information to function
 iris |>
   ds2dd_detailed(
     add.auto.id = TRUE,
     form.name = sample(c("b", "c"), size = 6, replace = TRUE, prob = rep(.5, 2))
   ) |>
   purrr::pluck("meta")
+#> # A tibble: 6 × 18
+#>   field_name   form_name section_header field_type field_label 
+#>   <chr>        <chr>     <lgl>          <chr>      <chr>       
+#> 1 record_id    b         NA             text       record_id   
+#> 2 sepal.length c         NA             text       Sepal.Length
+#> 3 sepal.width  b         NA             text       Sepal.Width 
+#> 4 petal.length c         NA             text       Petal.Length
+#> 5 petal.width  b         NA             text       Petal.Width 
+#> 6 species      c         NA             radio      Species     
+#> # ℹ 13 more variables: select_choices_or_calculations <chr>, 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>,
+#> #   question_number <lgl>, matrix_group_name <lgl>, matrix_ranking <lgl>,
+#> #   field_annotation <lgl>
 mtcars |> ds2dd_detailed(add.auto.id = TRUE)
+#> $data
+#> # A tibble: 32 × 12
+#>    record_id   mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
+#>        <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
+#>  1         1  21       6  160    110  3.9   2.62  16.5     0     1     4     4
+#>  2         2  21       6  160    110  3.9   2.88  17.0     0     1     4     4
+#>  3         3  22.8     4  108     93  3.85  2.32  18.6     1     1     4     1
+#>  4         4  21.4     6  258    110  3.08  3.22  19.4     1     0     3     1
+#>  5         5  18.7     8  360    175  3.15  3.44  17.0     0     0     3     2
+#>  6         6  18.1     6  225    105  2.76  3.46  20.2     1     0     3     1
+#>  7         7  14.3     8  360    245  3.21  3.57  15.8     0     0     3     4
+#>  8         8  24.4     4  147.    62  3.69  3.19  20       1     0     4     2
+#>  9         9  22.8     4  141.    95  3.92  3.15  22.9     1     0     4     2
+#> 10        10  19.2     6  168.   123  3.92  3.44  18.3     1     0     4     4
+#> # ℹ 22 more rows
+#> 
+#> $meta
+#> # A tibble: 12 × 18
+#>    field_name form_name section_header field_type field_label
+#>    <chr>      <chr>     <lgl>          <chr>      <chr>      
+#>  1 record_id  data      NA             text       record_id  
+#>  2 mpg        data      NA             text       mpg        
+#>  3 cyl        data      NA             text       cyl        
+#>  4 disp       data      NA             text       disp       
+#>  5 hp         data      NA             text       hp         
+#>  6 drat       data      NA             text       drat       
+#>  7 wt         data      NA             text       wt         
+#>  8 qsec       data      NA             text       qsec       
+#>  9 vs         data      NA             text       vs         
+#> 10 am         data      NA             text       am         
+#> 11 gear       data      NA             text       gear       
+#> 12 carb       data      NA             text       carb       
+#> # ℹ 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>,
+#> #   question_number <lgl>, matrix_group_name <lgl>, matrix_ranking <lgl>,
+#> #   field_annotation <lgl>
+#> 
+#> attr(,"class")
+#> [1] "REDCapCAST" "list"      
+
+## Using column name suffix to carry form name
 data <- iris |>
   ds2dd_detailed(add.auto.id = TRUE) |>
   purrr::pluck("data")
 names(data) <- glue::glue("{sample(x = c('a','b'),size = length(names(data)),
 replace=TRUE,prob = rep(x=.5,2))}__{names(data)}")
 data |> ds2dd_detailed(form.sep = "__")
-} # }
+#> $data
+#> # A tibble: 150 × 6
+#>    record_id sepal.length sepal.width petal.length petal.width species
+#>        <int>        <dbl>       <dbl>        <dbl>       <dbl> <fct>  
+#>  1         1          5.1         3.5          1.4         0.2 setosa 
+#>  2         2          4.9         3            1.4         0.2 setosa 
+#>  3         3          4.7         3.2          1.3         0.2 setosa 
+#>  4         4          4.6         3.1          1.5         0.2 setosa 
+#>  5         5          5           3.6          1.4         0.2 setosa 
+#>  6         6          5.4         3.9          1.7         0.4 setosa 
+#>  7         7          4.6         3.4          1.4         0.3 setosa 
+#>  8         8          5           3.4          1.5         0.2 setosa 
+#>  9         9          4.4         2.9          1.4         0.2 setosa 
+#> 10        10          4.9         3.1          1.5         0.1 setosa 
+#> # ℹ 140 more rows
+#> 
+#> $meta
+#> # A tibble: 6 × 18
+#>   field_name   form_name section_header field_type field_label 
+#>   <chr>        <chr>     <lgl>          <chr>      <chr>       
+#> 1 record_id    a         NA             text       record_id   
+#> 2 sepal.length a         NA             text       sepal.length
+#> 3 sepal.width  a         NA             text       sepal.width 
+#> 4 petal.length b         NA             text       petal.length
+#> 5 petal.width  b         NA             text       petal.width 
+#> 6 species      b         NA             radio      species     
+#> # ℹ 13 more variables: select_choices_or_calculations <chr>, 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>,
+#> #   question_number <lgl>, matrix_group_name <lgl>, matrix_ranking <lgl>,
+#> #   field_annotation <lgl>
+#> 
+#> attr(,"class")
+#> [1] "REDCapCAST" "list"