Skip to content

Commit

Permalink
Version 0.8.0 (#31)
Browse files Browse the repository at this point in the history
* improve test

* Increment minor version

* Update variable lists

* Increment version number

* shorten line length per `{lintr}`

* Remove unnecessary brackets.

* shorten line lengths per `{lintr}`

* Now need to get more rows

* Adding variable 'packs' (#28)

* Add a vector with demographic variables.

* Add a vector with LTC variables

* Add a vector with bedday variables

* Add a vector with cost variables.

* Add a vignette for variable packs

* Increment version number
  • Loading branch information
Moohan authored Jan 20, 2022
1 parent e14300d commit 1b14585
Show file tree
Hide file tree
Showing 18 changed files with 267 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.RData
.Ruserdata
docs
inst/doc
6 changes: 5 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: slfhelper
Title: Useful functions for working with the Source Linkage Files
Version: 0.7.1
Version: 0.8.0
Authors@R:
person("James", "McMahon", , "james.mcmahon@phs.scot", role = c("cre", "aut"),
comment = c(ORCID = "0000-0002-5380-2029"))
Expand Down Expand Up @@ -30,9 +30,13 @@ Imports:
tibble
Suggests:
covr,
knitr,
phsmethods,
rmarkdown,
spelling,
testthat (>= 3.0.0)
VignetteBuilder:
knitr
Remotes:
Public-Health-Scotland/phsmethods
Config/testthat/edition: 3
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# slfhelper 0.8.0

* Add a number of 'variable packs' for easily selecting sets of variables: `demog_vars`, `ltc_vars`, `ep_file_bedday_vars` and `ep_file_cost_vars`.
* Add a new vignette introducing variable packs.

# slfhelper 0.7.1

* Add check for server and hscdiip access on package load.
Expand Down
45 changes: 43 additions & 2 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,46 @@
#' @keywords data
"indiv_file_vars"

#' Demographic variables
#'
#' A vector containing the names of the demographic variables.
#'
#' @name demog_vars
#' @docType data
#' @keywords data
"demog_vars"

#' LTC variables
#'
#' A vector containing the names of the
#' Long Term Condition (LTC) variables.
#'
#' @name ltc_vars
#' @docType data
#' @keywords data
"ltc_vars"

#' Episode file bedday variables
#'
#' A vector containing the names of the
#' bedday related variables in the
#' episode file.
#'
#' @name ep_file_bedday_vars
#' @docType data
#' @keywords data
"ep_file_bedday_vars"

#' Episode file cost variables
#'
#' A vector containing the names of the
#' cost related variables in the
#' episode file.
#'
#' @name ep_file_cost_vars
#' @docType data
#' @keywords data
"ep_file_cost_vars"

#' HSCP name / code lookup
#'
Expand Down Expand Up @@ -51,8 +91,9 @@
#' @keywords data
"recids"

#' A [tibble][tibble::tibble-package] containing an example cohort of CHI numbers under different
#' variable names. It is used for testing and to illustrate examples.
#' A [tibble][tibble::tibble-package] containing an example
#' cohort of CHI numbers under different variable names.
#' It is used for testing and to illustrate examples.
#' It is likely that many of the 'chi numbers' are not valid.
#'
#' @name chi_cohort
Expand Down
20 changes: 10 additions & 10 deletions R/read_slf.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ read_slf <-
# but the column wasn't selected we need to add it (and remove later)
remove_partnership_var <- FALSE
remove_recid_var <- FALSE
if (!(is.null(optional_params$columns))) {
if (!(is.null(partnerships)) &
if (!is.null(optional_params$columns)) {
if (!is.null(partnerships) &
!("hscp2018" %in% optional_params$columns)) {
optional_params$columns <- c(optional_params$columns, "hscp2018")
remove_partnership_var <- TRUE
}
if (!(is.null(recids)) & file_version == "episode" &
if (!is.null(recids) & file_version == "episode" &
!("recid" %in% optional_params$columns)) {
optional_params$columns <- c(optional_params$columns, "recid")
remove_recid_var <- TRUE
Expand Down Expand Up @@ -66,15 +66,15 @@ read_slf <-
# If a partnership is specified filter first;
# With testing it seems to usually be faster if we do partnership
# filtering before recid filtering
if (!(is.null(partnerships))) {
if (!is.null(partnerships)) {
slfs_list <- purrr::map(
slfs_list,
~ dplyr::filter(.x, .x$hscp2018 %in% partnerships)
)
}

# If a recid is specified filter now
if (!(is.null(recids))) {
if (!is.null(recids)) {
slfs_list <- purrr::map(
slfs_list,
~ dplyr::filter(.x, .x$recid %in% recids)
Expand Down Expand Up @@ -134,9 +134,9 @@ read_slf_episode <-
read_slf(
year = year,
file_version = "episode",
partnerships = partnerships,
recids = recids,
columns = columns,
partnerships = unique(partnerships),
recids = unique(recids),
columns = unique(columns),
...
)
)
Expand Down Expand Up @@ -174,8 +174,8 @@ read_slf_individual <-
read_slf(
year = year,
file_version = "individual",
partnerships = partnerships,
columns = columns,
partnerships = unique(partnerships),
columns = unique(columns),
...
)
)
Expand Down
Binary file added data/demog_vars.rda
Binary file not shown.
Binary file added data/ep_file_bedday_vars.rda
Binary file not shown.
Binary file added data/ep_file_cost_vars.rda
Binary file not shown.
Binary file added data/ltc_vars.rda
Binary file not shown.
12 changes: 7 additions & 5 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
NSS
Bedday
HSCP
LTC
ORCID
RStudio
Recid
Rmd
SLFs
bedday
beddays
dplyr
fst
hscdiip
hscp
recid
recids
tibble
hscdiip
PHS
ORCID
10 changes: 6 additions & 4 deletions man/chi_cohort.Rd

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

16 changes: 16 additions & 0 deletions man/demog_vars.Rd

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

18 changes: 18 additions & 0 deletions man/ep_file_bedday_vars.Rd

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

18 changes: 18 additions & 0 deletions man/ep_file_cost_vars.Rd

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

17 changes: 17 additions & 0 deletions man/ltc_vars.Rd

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

12 changes: 10 additions & 2 deletions tests/testthat/test-gen_file_path.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
test_that("Produces single episode file path", {
path <- gen_file_path("1718", "episode")

expect_identical(path, fs::path("/conf/hscdiip/01-Source-linkage-files/source-episode-file-201718.fst"))
expect_identical(path, fs::path(
"/conf/hscdiip",
"01-Source-linkage-files",
"source-episode-file-201718.fst"
))

expect_identical(fs::path_ext(path), "fst")

Expand All @@ -12,7 +16,11 @@ test_that("Produces single episode file path", {
test_that("Produces single individual file path", {
path <- gen_file_path("1718", "individual")

expect_identical(path, fs::path("/conf/hscdiip/01-Source-linkage-files/source-individual-file-201718.fst"))
expect_identical(path, fs::path(
"/conf/hscdiip",
"01-Source-linkage-files",
"source-individual-file-201718.fst"
))

expect_identical(fs::path_ext(path), "fst")

Expand Down
2 changes: 2 additions & 0 deletions vignettes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.html
*.R
Loading

0 comments on commit 1b14585

Please sign in to comment.