Skip to content

Commit

Permalink
Pass the slf_postcode_lookup as data instead of the path
Browse files Browse the repository at this point in the history
  • Loading branch information
Moohan committed Aug 7, 2023
1 parent 54802ac commit f417fbe
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
28 changes: 17 additions & 11 deletions R/add_hri_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
#' }
#' The intention is to only keep the records where keep_flag = 0
#'
#' @param data A data frame, usually an SLF Individual File
#' @param slf_pc_lookup_path The path to the Source postcode lookup, defaults
#' to [get_slf_postcode_path()]
#' @inheritParams add_hri_variables

Check failure on line 13 in R/add_hri_variables.R

View workflow job for this annotation

GitHub Actions / Check Spelling

`hri` is not a recognized word. (unrecognized-spelling)
#'
#' @return A data frame with the variable 'keep_flag'
flag_non_scottish_residents <- function(data,
slf_pc_lookup_path = get_slf_postcode_path()) {
flag_non_scottish_residents <- function(
data,
slf_pc_lookup) {
check_variables_exist(data, c("postcode", "gpprac"))

# Make a lookup of postcode areas, which consist of the first characters
# of the postcode
pc_areas <- arrow::read_parquet(slf_pc_lookup_path) %>%
pc_areas <- slf_pc_lookup %>%
dplyr::mutate(
pc_area = stringr::str_match(postcode, "^[A-Z]{1,3}"),
scot_flag = 0L
Expand Down Expand Up @@ -56,13 +55,20 @@ flag_non_scottish_residents <- function(data,
#' creates a lookup where HRIs are calculated at Scotland, Health Board, and

Check failure on line 55 in R/add_hri_variables.R

View workflow job for this annotation

GitHub Actions / Check Spelling

`HRIs` is not a recognized word. (unrecognized-spelling)
#' LCA level. Then joins on this lookup by chi/anon_chi.
#'
#' @param data An SLF individual file
#' @param chi_variable Defaults to "anon_chi"
#' @param data An SLF individual file.
#' @param chi_variable Defaults to "anon_chi".
#' @param slf_pc_lookup The Source postcode lookup, defaults
#' to [get_slf_postcode_path()] read using [read_file()].
#'
#' @return The individual file with HRI variables matched on
#' @export
add_hri_variables <- function(data,
chi_variable = "anon_chi") {
add_hri_variables <- function(

Check failure on line 65 in R/add_hri_variables.R

View workflow job for this annotation

GitHub Actions / Check Spelling

`hri` is not a recognized word. (unrecognized-spelling)
data,
chi_variable = "anon_chi",
slf_pc_lookup = read_file(
get_slf_postcode_path(),
col_select = "postcode"
)) {
hri_lookup <- data %>%

Check failure on line 72 in R/add_hri_variables.R

View workflow job for this annotation

GitHub Actions / Check Spelling

`hri` is not a recognized word. (unrecognized-spelling)
dplyr::select(
"year",
Expand All @@ -82,7 +88,7 @@ add_hri_variables <- function(data,
"pis_paid_items",
"ooh_cases"
) %>%
flag_non_scottish_residents() %>%
flag_non_scottish_residents(slf_pc_lookup = slf_pc_lookup) %>%
dplyr::filter(keep_flag == 0L) %>%
# Scotland cost and proportion
dplyr::mutate(
Expand Down
13 changes: 10 additions & 3 deletions man/add_hri_variables.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/flag_non_scottish_residents.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f417fbe

Please sign in to comment.