knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
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.
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!
library(slfhelper)
library(slfhelper) ep_data <- read_slf_episode(year = 1920, columns = c("year", "anon_chi", "recid")) indiv_data <- read_slf_individual(year = 1920, columns = c("year", "anon_chi", "nsu"))
To help with the task of picking which variables you might need for your analysis, as well as getting the spelling correct, we provide lists of the variable names in the package.
# Show the first few variables from the episode file head(ep_file_vars) # Do the same for the individual file head(indiv_file_vars)
This is great but it can still be a lot of effort and copy/pasting every time, especially if you need quite a few variables for your analysis.
To assist with this, there are a number of 'variable packs', these are groups of variables which would commonly be needed together which can be accessed with a simple name. Currently there are four packs; demog_vars
, ltc_vars
, ep_file_bedday_vars
and ep_file_cost_vars
. Let's see what they contain.
These are demographic variables which are specific to CHI and can be used with episode or individual file.
demog_vars
These are the Long Term Condition flag variables which are specific to CHI and can be used with episode or individual file.
ltc_vars
These are variables detailing beddays, they are specific to an episode and can only be used with the episode file.
ep_file_bedday_vars
These are variables detailing costs, they are specific to an episode and can only be used with the episode file.
ep_file_cost_vars
These variable packs can be used in the column selection to simplify your code substantially.
For example to take some demographic data and LTC flags from the individual file.
library(slfhelper) indiv_ltc_data <- read_slf_individual(year = 1920, columns = c("year", demog_vars, ltc_vars))
Or to get bedday information about Acute records from the episode file.
library(slfhelper) acute_beddays <- read_slf_episode( year = 1920, columns = c("year", "anon_chi", "hbtreatcode", "recid", ep_file_bedday_vars, "cij_pattype"), recid = c("01B", "GLS") )
You should be using the column
argument when reading in data to increase the read speed, and reduce the amount of data you are loading into R. slfhelper
provides a number of helpers to make picking and using the variables you need easier.
If you would like any changes made to any existing packs, please open an issue on GitHub.
If you would like to suggest any additional variable packs, either open an issue, or even submit a pull request!
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.