Skip to content

Commit

Permalink
replace columns by col_select and add tidyselect
Browse files Browse the repository at this point in the history
  • Loading branch information
lizihao-anu committed Aug 16, 2024
1 parent 79148e5 commit fb509d0
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions vignettes/variable-packs.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,37 @@ knitr::opts_chunk$set(

## Selecting only specified variables

It is recommended to only choose the variables you need when reading in a Source Linkage File. This can be achieved by specifying a `column` argument to the relevant `read_slf_` function.
It is recommended to only choose the variables you need when reading in a Source Linkage File. This can be achieved by specifying a `col_select` argument to the relevant `read_slf_` function.

This will result in the data being read in much faster as well as being easy to work with. The full episode and individual files have 200+ and 100+ variables respectively!


```{r load-package, include=FALSE}
library(slfhelper)
```

```{r column-example, eval=FALSE}
library(slfhelper)
ep_data <- read_slf_episode(year = 1920, columns = c("year", "anon_chi", "recid"))
ep_data <- read_slf_episode(year = 1920, col_select = c("year", "anon_chi", "recid"))
indiv_data <- read_slf_individual(year = 1920, col_select = c("year", "anon_chi", "nsu"))
```

indiv_data <- read_slf_individual(year = 1920, columns = c("year", "anon_chi", "nsu"))
## Selecting variables using `tidyselect` functions
It is now allowed to use `tidyselect` functions, such as `contains()` and `start_with()`, to select variables in relevant `read_slf_` function. One can also mix `tidyselect` functions with specified variables when selecting.

```{r tidyselect, eval=FALSE}
library(slfhelper)
ep_data <-
read_slf_episode(year = 1920,
col_select = !tidyselect::contains("keytime"))
indiv_data <-
read_slf_individual(
year = 1920,
col_select = c("year", "anon_chi", "nsu", tidyselect::starts_with("sds"))
)
```

## Looking up variable names
Expand Down Expand Up @@ -85,7 +102,7 @@ For example to take some demographic data and LTC flags from the individual file
```{r use-ltc-indiv, eval=FALSE}
library(slfhelper)
indiv_ltc_data <- read_slf_individual(year = 1920, columns = c("year", demog_vars, ltc_vars))
indiv_ltc_data <- read_slf_individual(year = 1920, col_select = c("year", demog_vars, ltc_vars))
```


Expand All @@ -95,7 +112,7 @@ library(slfhelper)
acute_beddays <- read_slf_episode(
year = 1920,
columns = c("year", "anon_chi", "hbtreatcode", "recid", ep_file_bedday_vars, "cij_pattype"),
col_select = c("year", "anon_chi", "hbtreatcode", "recid", ep_file_bedday_vars, "cij_pattype"),
recid = c("01B", "GLS")
)
```
Expand Down

0 comments on commit fb509d0

Please sign in to comment.