Skip to contents

Take a supertibble generated with read_redcap() and return a named list of data tibbles.

Usage

extract_tibbles(supertbl, tbls = everything())

Arguments

supertbl

A supertibble generated by read_redcap(). Required.

tbls

A vector of form_names or a tidyselect helper. Default is dplyr::everything().

Value

A named list of tibbles

Details

This function makes it easy to extract a multiple instrument's data from a REDCapTidieR supertibble into a named list. Specifying instruments using tidyselect helper functions such as dplyr::starts_with() or dplyr::ends_with() is supported.

Examples

superheroes_supertbl
#> # A REDCapTidieR Supertibble with 2 instruments
#>   redcap_form_name   redcap_form_label  redcap_data redcap_metadata    structure
#>   <chr>              <chr>              <list>      <list>             <chr>    
#> 1 heroes_information Heroes Information <tibble>    <tibble [11 × 17]> nonrepea…
#> 2 super_hero_powers  Super Hero Powers  <tibble>    <tibble [2 × 17]>  repeating
#> # ℹ 4 more variables: data_rows <int>, data_cols <int>, data_size <lbstr_by>,
#> #   data_na_pct <formttbl>

# Extract all data tibbles
extract_tibbles(superheroes_supertbl)
#> $heroes_information
#> # A tibble: 734 × 12
#>    record_id name      gender eye_color race  hair_color height weight publisher
#>        <dbl> <chr>     <chr>  <chr>     <chr> <chr>       <dbl>  <dbl> <chr>    
#>  1         0 A-Bomb    Male   yellow    Human No Hair       203    441 Marvel C…
#>  2         1 Abe Sapi… Male   blue      Icth… No Hair       191     65 Dark Hor…
#>  3         2 Abin Sur  Male   blue      Unga… No Hair       185     90 DC Comics
#>  4         3 Abominat… Male   green     Huma… No Hair       203    441 Marvel C…
#>  5         4 Abraxas   Male   blue      Cosm… Black         -99    -99 Marvel C…
#>  6         5 Absorbin… Male   blue      Human No Hair       193    122 Marvel C…
#>  7         6 Adam Mon… Male   blue      -     Blond         -99    -99 NBC - He…
#>  8         7 Adam Str… Male   blue      Human Blond         185     88 DC Comics
#>  9         8 Agent 13  Female blue      -     Blond         173     61 Marvel C…
#> 10         9 Agent Bob Male   brown     Human Brown         178     81 Marvel C…
#> # ℹ 724 more rows
#> # ℹ 3 more variables: skin_color <chr>, alignment <chr>,
#> #   form_status_complete <fct>
#> 
#> $super_hero_powers
#> # A tibble: 5,966 × 4
#>    record_id redcap_repeat_instance power               form_status_complete
#>        <dbl>                  <dbl> <chr>               <fct>               
#>  1         0                      1 Accelerated Healing Incomplete          
#>  2         0                      2 Durability          Incomplete          
#>  3         0                      3 Longevity           Incomplete          
#>  4         0                      4 Super Strength      Incomplete          
#>  5         0                      5 Stamina             Incomplete          
#>  6         0                      6 Camouflage          Incomplete          
#>  7         0                      7 Self-Sustenance     Incomplete          
#>  8         1                      1 Agility             Incomplete          
#>  9         1                      2 Accelerated Healing Incomplete          
#> 10         1                      3 Cold Resistance     Incomplete          
#> # ℹ 5,956 more rows
#> 

# Only extract data tibbles starting with "heroes"
extract_tibbles(superheroes_supertbl, starts_with("heroes"))
#> $heroes_information
#> # A tibble: 734 × 12
#>    record_id name      gender eye_color race  hair_color height weight publisher
#>        <dbl> <chr>     <chr>  <chr>     <chr> <chr>       <dbl>  <dbl> <chr>    
#>  1         0 A-Bomb    Male   yellow    Human No Hair       203    441 Marvel C…
#>  2         1 Abe Sapi… Male   blue      Icth… No Hair       191     65 Dark Hor…
#>  3         2 Abin Sur  Male   blue      Unga… No Hair       185     90 DC Comics
#>  4         3 Abominat… Male   green     Huma… No Hair       203    441 Marvel C…
#>  5         4 Abraxas   Male   blue      Cosm… Black         -99    -99 Marvel C…
#>  6         5 Absorbin… Male   blue      Human No Hair       193    122 Marvel C…
#>  7         6 Adam Mon… Male   blue      -     Blond         -99    -99 NBC - He…
#>  8         7 Adam Str… Male   blue      Human Blond         185     88 DC Comics
#>  9         8 Agent 13  Female blue      -     Blond         173     61 Marvel C…
#> 10         9 Agent Bob Male   brown     Human Brown         178     81 Marvel C…
#> # ℹ 724 more rows
#> # ℹ 3 more variables: skin_color <chr>, alignment <chr>,
#> #   form_status_complete <fct>
#>