From 4c1650d528a3bf52ba5d69b43fe5f8f58fa51022 Mon Sep 17 00:00:00 2001 From: agdamsbo <43278243+agdamsbo@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:41:50 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20agdamsbo?= =?UTF-8?q?/REDCapCAST@18544ddcfe0d2084aafed5931618789bcd4173e7=20?= =?UTF-8?q?=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgdown.yml | 2 +- reference/REDCapCAST-package.html | 3 +- reference/as_factor.character.html | 8 ++ reference/as_factor.factor.html | 8 ++ reference/as_factor.haven_labelled.html | 8 ++ reference/as_factor.html | 161 ++++++++++++++++++++++ reference/as_factor.labelled.html | 8 ++ reference/as_factor.logical.html | 8 ++ reference/as_factor.numeric.html | 8 ++ reference/ds2dd_detailed.html | 172 +----------------------- reference/fct2num.html | 124 +++++++++++++++++ reference/get_attr.html | 114 +--------------- reference/haven_all_levels.html | 2 +- reference/index.html | 18 +++ reference/named_levels.html | 107 +++++++++++++++ reference/numchar2fct.html | 14 +- reference/parse_data.html | 16 +-- reference/set_attr.html | 8 +- reference/var2fct.html | 10 +- search.json | 2 +- sitemap.xml | 3 + 21 files changed, 488 insertions(+), 316 deletions(-) create mode 100644 reference/as_factor.character.html create mode 100644 reference/as_factor.factor.html create mode 100644 reference/as_factor.haven_labelled.html create mode 100644 reference/as_factor.html create mode 100644 reference/as_factor.labelled.html create mode 100644 reference/as_factor.logical.html create mode 100644 reference/as_factor.numeric.html create mode 100644 reference/fct2num.html create mode 100644 reference/named_levels.html diff --git a/pkgdown.yml b/pkgdown.yml index bc120aa..711f065 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-19T12:19Z +last_built: 2024-11-20T13:41Z urls: reference: https://agdamsbo.github.io/REDCapCAST/reference article: https://agdamsbo.github.io/REDCapCAST/articles diff --git a/reference/REDCapCAST-package.html b/reference/REDCapCAST-package.html index 22bcf11..2dea0d6 100644 --- a/reference/REDCapCAST-package.html +++ b/reference/REDCapCAST-package.html @@ -62,7 +62,8 @@ Casting metadata for REDCap database creation and handling of castellated data u

Author

Maintainer: Andreas Gammelgaard Damsbo agdamsbo@clin.au.dk (ORCID)

-
+

Authors:

diff --git a/reference/as_factor.character.html b/reference/as_factor.character.html new file mode 100644 index 0000000..9a11615 --- /dev/null +++ b/reference/as_factor.character.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/reference/as_factor.factor.html b/reference/as_factor.factor.html new file mode 100644 index 0000000..9a11615 --- /dev/null +++ b/reference/as_factor.factor.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/reference/as_factor.haven_labelled.html b/reference/as_factor.haven_labelled.html new file mode 100644 index 0000000..9a11615 --- /dev/null +++ b/reference/as_factor.haven_labelled.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/reference/as_factor.html b/reference/as_factor.html new file mode 100644 index 0000000..75fb26c --- /dev/null +++ b/reference/as_factor.html @@ -0,0 +1,161 @@ + +Convert labelled vectors to factors while preserving attributes — as_factor • REDCapCAST + Skip to contents + + +
+
+
+ +
+

This extends [forcats::as_factor()] as well as [haven::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.

+
+ +
+

Usage

+
as_factor(x, ...)
+
+# S3 method for class 'factor'
+as_factor(x, ...)
+
+# S3 method for class 'logical'
+as_factor(x, ...)
+
+# S3 method for class 'numeric'
+as_factor(x, ...)
+
+# S3 method for class 'character'
+as_factor(x, ...)
+
+# S3 method for class 'haven_labelled'
+as_factor(
+  x,
+  levels = c("default", "labels", "values", "both"),
+  ordered = FALSE,
+  ...
+)
+
+# S3 method for class 'labelled'
+as_factor(
+  x,
+  levels = c("default", "labels", "values", "both"),
+  ordered = FALSE,
+  ...
+)
+
+ +
+

Arguments

+ + +
x
+

Object to coerce to a factor.

+ + +
...
+

Other arguments passed down to method.

+ + +
levels
+

How to create the levels of the generated factor:

+

* "default": uses labels where available, otherwise the values. + Labels are sorted by value. + * "both": like "default", but pastes together the level and value + * "label": use only the labels; unlabelled values become `NA` + * "values": use only the values

+ + +
ordered
+

If `TRUE` create an ordered (ordinal) factor, if +`FALSE` (the default) create a regular (nominal) factor.

+ +
+
+

Details

+

Please refer to parent functions for extended documentation. +To avoid redundancy calls and errors, functions are copy-pasted here

+
+ +
+

Examples

+
# will preserve all attributes
+c(1, 4, 3, "A", 7, 8, 1) |> as_factor()
+#> [1] 1 4 3 A 7 8 1
+#> Levels: 1 4 3 A 7 8
+structure(c(1, 2, 3, 2, 10, 9),
+  labels = c(Unknown = 9, Refused = 10)
+) |>
+  as_factor() |> dput()
+#> structure(c(1L, 2L, 3L, 2L, 5L, 4L), levels = c("1", "2", "3", 
+#> "9", "10"), class = "factor", labels = c(Unknown = 9, Refused = 10
+#> ))
+
+structure(c(1, 2, 3, 2, 10, 9),
+  labels = c(Unknown = 9, Refused = 10),
+  class = "haven_labelled"
+) |>
+  as_factor()
+#> [1] 1       2       3       2       Refused Unknown
+#> attr(,"labels")
+#> Unknown Refused 
+#>       9      10 
+#> Levels: 1 2 3 Unknown Refused
+
+
+
+ + +
+ + + + + + + diff --git a/reference/as_factor.labelled.html b/reference/as_factor.labelled.html new file mode 100644 index 0000000..9a11615 --- /dev/null +++ b/reference/as_factor.labelled.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/reference/as_factor.logical.html b/reference/as_factor.logical.html new file mode 100644 index 0000000..9a11615 --- /dev/null +++ b/reference/as_factor.logical.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/reference/as_factor.numeric.html b/reference/as_factor.numeric.html new file mode 100644 index 0000000..9a11615 --- /dev/null +++ b/reference/as_factor.numeric.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/reference/ds2dd_detailed.html b/reference/ds2dd_detailed.html index 5cbf0ca..911e29f 100644 --- a/reference/ds2dd_detailed.html +++ b/reference/ds2dd_detailed.html @@ -142,190 +142,24 @@ Please, do always inspect the data dictionary before upload.

Examples

-
data <- REDCapCAST::redcapcast_data
+    
if (FALSE) { # \dontrun{
+data <- REDCapCAST::redcapcast_data
 data |> ds2dd_detailed()
-#> $data
-#> # A tibble: 25 × 27
-#>    record_id redcap_event_name redcap_repeat_instrument redcap_repeat_instance
-#>        <dbl> <chr>             <chr>                                     <dbl>
-#>  1         1 inclusion         NA                                           NA
-#>  2         2 inclusion         NA                                           NA
-#>  3         2 follow1           NA                                           NA
-#>  4         2 follow1           New Event (?)                                 1
-#>  5         3 inclusion         NA                                           NA
-#>  6         3 follow1           NA                                           NA
-#>  7         3 follow2           NA                                           NA
-#>  8         3 follow1           New Event (?)                                 1
-#>  9         3 follow1           New Event (?)                                 2
-#> 10         3 follow2           New Event (?)                                 1
-#> # ℹ 15 more rows
-#> # ℹ 23 more variables: cpr <chr>, inclusion <date>, inclusion_time <chr>,
-#> #   dob <date>, age <dbl>, age_integer <dbl>, sex <chr>, 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>, …
-#> 
-#> $meta
-#> # A tibble: 27 × 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 redcap_event_name        data      NA             text       redcap_event_na…
-#>  3 redcap_repeat_instrument data      NA             text       redcap_repeat_i…
-#>  4 redcap_repeat_instance   data      NA             text       redcap_repeat_i…
-#>  5 cpr                      data      NA             text       cpr             
-#>  6 inclusion                data      NA             text       inclusion       
-#>  7 inclusion_time           data      NA             text       inclusion_time  
-#>  8 dob                      data      NA             text       dob             
-#>  9 age                      data      NA             text       age             
-#> 10 age_integer              data      NA             text       age_integer     
-#> # ℹ 17 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>
-#> 
 iris |> ds2dd_detailed(add.auto.id = TRUE)
-#> A default id column has been added
-#> $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>
-#> 
 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 default id column has been added
-#> # A tibble: 6 × 18
-#>   field_name   form_name section_header field_type field_label 
-#>   <chr>        <chr>     <lgl>          <chr>      <chr>       
-#> 1 record_id    c         NA             text       record_id   
-#> 2 sepal.length b         NA             text       sepal.length
-#> 3 sepal.width  b         NA             text       sepal.width 
-#> 4 petal.length b         NA             text       petal.length
-#> 5 petal.width  c         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)
-#> A default id column has been added
-#> $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>
-#> 
 data <- iris |>
   ds2dd_detailed(add.auto.id = TRUE) |>
   purrr::pluck("data")
-#> A default id column has been added
 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    b         NA             text       record_id   
-#> 2 sepal.length b         NA             text       sepal.length
-#> 3 sepal.width  b         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>
-#> 
+} # }