diff --git a/DESCRIPTION b/DESCRIPTION index fd929df..c80ed49 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,10 +1,10 @@ Package: phsmethods Title: Standard Methods for use in Public Health Scotland -Version: 0.1.1 +Version: 0.2.0 Authors@R: c( - person("Jack", "Hannah", email = "jack.hannah1@nhs.net", role = c("aut", "cre")), - person("David", "Caldwell", email = "david.caldwell1@nhs.net", role = c("aut", "rev")), + person("David", "Caldwell", email = "david.caldwell1@nhs.net", role = c("aut", "cre")), person("Lucinda", "Lawrie", email = "lucinda.lawrie1@nhs.net", role = "rev"), + person("Jack", "Hannah", role = "aut"), person("Tina", "Fu", email = "tina.fu@nhs.net", role = "aut"), person("Ciara", "Gribben", email = "ciaragribben@nhs.net", role = "aut"), person("Chris", "Deans", email = "chrisdeans@nhs.net", role = "aut"), diff --git a/NEWS.md b/NEWS.md index d2be6d6..9f1b2cc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,15 @@ +# phsmethods 0.2.0 (2020-04-17) + +- New functions added: `age_group()`([#23](https://github.com/Health-SocialCare-Scotland/phsmethods/issues/23), [@chrisdeans](https://github.com/chrisdeans)); `chi_check()`([#30](https://github.com/Health-SocialCare-Scotland/phsmethods/issues/30), [@graemegowans](https://github.com/graemegowans)); `chi_pad()`([#30](https://github.com/Health-SocialCare-Scotland/phsmethods/issues/30), [@graemegowans](https://github.com/graemegowans)); and `match_area()`([#13](https://github.com/Health-SocialCare-Scotland/phsmethods/issues/13), [@jvillacampa](https://github.com/jvillacampa)). + +- The first argument of `postcode()` is now `x`, as opposed to `string`. This is unlikely to break much, if any, existing code. `postcode()` is also now slightly faster. + +- `phsmethods` no longer imports `stringi`. + +- `phsmethods` now depends on a version of R >= 2.10. + +- [Jack Hannah](https://github.com/jackhannah95) is no longer a maintainer. + # phsmethods 0.1.1 (2020-02-10) - `file_size()`, `fin_year()`, `qtr()`, `qtr_end()`, `qtr_next()` and `qtr_prev()` now use `inherits(x, "y")` instead of `class(x) == "y"` to check class. The reasoning is explained in this [blogpost by Martin Maechler](https://developer.r-project.org/Blog/public/2019/11/09/when-you-think-class.-think-again/index.html). diff --git a/R/age_group.R b/R/age_group.R index e465873..e78a06f 100644 --- a/R/age_group.R +++ b/R/age_group.R @@ -1,19 +1,19 @@ #' Create age groups #' #' @description -#' age_group() takes a numeric vector and assigns each age to the appropriate -#' age group. +#' \code{age_group()} takes a numeric vector and assigns each age to the +#' appropriate age group. #' #' @param x a vector of numeric values #' @param from the start of the smallest age group. The default is \code{0}. #' @param to the end point of the age groups. The default is \code{90}. #' @param by the size of the age groups. The default is \code{5}. #' @param as_factor The default behaviour is to return a character vector. Use -#' \code{TRUE} to return a factor vector instead. +#' \code{TRUE} to return a factor vector instead. #' #' @return A character vector, where each element is the age group for the -#' corresponding element in \code{x}. If \code{as_factor = TRUE} a factor -#' vector is returned instead. +#' corresponding element in \code{x}. If \code{as_factor = TRUE}, a factor +#' vector is returned instead. #' #' @details #' The \code{from}, \code{to} and \code{by} values are used to create distinct @@ -63,8 +63,10 @@ age_group <- function(x, right = FALSE, ordered_result = TRUE) - if(as_factor == FALSE) + if (as_factor == FALSE) { agegroup <- as.character(agegroup) + } agegroup + } diff --git a/R/chi.R b/R/chi.R index f5fbd9f..8cd8271 100644 --- a/R/chi.R +++ b/R/chi.R @@ -89,7 +89,7 @@ checksum <- function(x) { sub_num(x, 9) j <- floor(i / 11) # Discard remainder - k <- 11 * (j + 1) - i # Check sum calculation + k <- 11 * (j + 1) - i # Checksum calculation k <- ifelse(k == 11, 0, k) # If 11, make 0 # Check if output matches the checksum diff --git a/R/file_size.R b/R/file_size.R index 70aab34..beb16ba 100644 --- a/R/file_size.R +++ b/R/file_size.R @@ -91,8 +91,7 @@ file_size <- function(filepath = getwd(), pattern = NULL) { } y <- x %>% - purrr::map(~file.info(paste0(filepath, "/", .))$size) %>% - unlist() %>% + purrr::map_dbl(~file.info(paste0(filepath, "/", .))$size) %>% # The gdata package defines a kilobyte (KB) as 1,000 bytes, and a # kibibyte (KiB) as 1,024 bytes diff --git a/R/fin_year.R b/R/fin_year.R index 0e72a58..2ab0bee 100644 --- a/R/fin_year.R +++ b/R/fin_year.R @@ -19,7 +19,7 @@ fin_year <- function(date) { if (!inherits(date, c("Date", "POSIXct"))) { - stop("The input must have Date or POSIXct class.") + stop("The input must have Date or POSIXct class") } # Simply converting all elements of the input vector resulted in poor diff --git a/R/match_area.R b/R/match_area.R index bcc8806..ec8ad62 100644 --- a/R/match_area.R +++ b/R/match_area.R @@ -76,15 +76,15 @@ match_area <- function(x) { "\U2022 RA2704: Unknown Residency")) } - # Reading area code to name lookup + # Load area code to name lookup area_lookup <- phsmethods::area_lookup - # Transforming variable into data frame to allow merging with lookup + # Transform variable into data frame to allow merging with lookup code_var <- tibble::enframe(code_var, name = NULL, value = "geo_code") - # Merging lookup with code variable and retrieving only the name + # Merge lookup with code variable and retrieving only the name dplyr::left_join(code_var, area_lookup, by = "geo_code") %>% diff --git a/R/phsmethods.R b/R/phsmethods.R index f1d2a77..2c63944 100644 --- a/R/phsmethods.R +++ b/R/phsmethods.R @@ -16,4 +16,4 @@ NULL # Stops notes from appearing in R CMD check because of undefined global # variable '.' and allows area_lookup dataset to be used inside match_area # function -utils::globalVariables(c(".", "area_lookup")) +if(getRversion() >= "2.15.1") utils::globalVariables(c(".", "area_lookup")) diff --git a/R/qtr.R b/R/qtr.R index c7fe496..e638417 100644 --- a/R/qtr.R +++ b/R/qtr.R @@ -7,13 +7,13 @@ #' value. #' #' \itemize{ -#' \item \code{qtr} returns the current quarter. +#' \item \code{qtr} returns the current quarter #' -#' \item \code{qtr_end} returns the last month in the quarter. +#' \item \code{qtr_end} returns the last month in the quarter #' -#' \item \code{qtr_next} returns the next quarter. +#' \item \code{qtr_next} returns the next quarter #' -#' \item \code{qtr_prev} returns the previous quarter. +#' \item \code{qtr_prev} returns the previous quarter #' } #' #' @details Quarters are defined as: @@ -44,7 +44,7 @@ qtr <- function(date, format = c("long", "short")) { format <- match.arg(format) if (!inherits(date, "Date")) { - stop("The input must have Date class.") + stop("The input must have Date class") } quarter_num <- lubridate::quarter(date) @@ -80,7 +80,7 @@ qtr_end <- function(date, format = c("long", "short")) { format <- match.arg(format) if (!inherits(date, "Date")) { - stop("The input must have Date class.") + stop("The input must have Date class") } quarter_num <- lubridate::quarter(date) @@ -116,7 +116,7 @@ qtr_next <- function(date, format = c("long", "short")) { format <- match.arg(format) if (!inherits(date, "Date")) { - stop("The input must have Date class.") + stop("The input must have Date class") } quarter_num <- lubridate::quarter(date) @@ -152,7 +152,7 @@ qtr_prev <- function(date, format = c("long", "short")) { format <- match.arg(format) if (!inherits(date, "Date")) { - stop("The input must have Date class.") + stop("The input must have Date class") } quarter_num <- lubridate::quarter(date) diff --git a/README.Rmd b/README.Rmd index a2a92f0..c220f11 100644 --- a/README.Rmd +++ b/README.Rmd @@ -20,8 +20,12 @@ knitr::opts_chunk$set( `phsmethods` contains functions for commonly undertaken analytical tasks in [Public Health Scotland (PHS)](https://www.publichealthscotland.scot/): +- `age_group()` categorises ages into groups +- `chi_check()` assesses the validity of a CHI number +- `chi_pad()` adds a leading zero to nine-digit CHI numbers - `file_size()` returns the names and sizes of files in a directory - `fin_year()` assigns a date to a financial year in the format `YYYY/YY` +- `match_area()` converts geography codes into area names - `postcode()` formats improperly recorded postcodes - `qtr()`, `qtr_end()`, `qtr_next()` and `qtr_prev()` assign a date to a quarter @@ -60,6 +64,35 @@ To access the help file for any of `phsmethods`' functions, type `?function_name ?postcode ``` +### age_group + +```{r age_group} +a <- c(54, 7, 77, 1, 26, 101) + +# By default age_group goes in 5 year increments from 0 to 90+ +age_group(a) + +# But these settings can be changed +age_group(a, from = 0, to = 80, by = 10) +``` + +### chi_check + +```{r chi_check, message = FALSE, warning = FALSE} +# chi_check returns specific feedback on why a CHI number might be invalid +library(dplyr) +b <- tibble(chi = c("0101011237", "3213201234", "123456789", "12345678900", "010120123?")) +b %>% mutate(validity = chi_check(chi)) +``` + +### chi_pad + +```{r chi_pad} +# Only nine-digit characters are prefixed with a zero +chi_pad(c("101011237", "101201234", "123223")) +``` + + ### file_size ```{r file_size} @@ -67,19 +100,28 @@ To access the help file for any of `phsmethods`' functions, type `?function_name file_size(testthat::test_path("files")) # Names and sizes of Excel files only in the tests/testthat/files folder -file_size(testthat::test_path("files"), pattern = ".xlsx?$") +file_size(testthat::test_path("files"), pattern = "\\.xlsx?$") ``` ### fin_year ```{r fin_year} -a <- lubridate::dmy(c(21012017, 04042017, 17112017)) -fin_year(a) +c <- lubridate::dmy(c(21012017, 04042017, 17112017)) +fin_year(c) +``` + +### match_area + +```{r match_area} +match_area("S13002781") + +d <- tibble(code = c("S02000656", "S02001042", "S08000020", "S12000013", "S13002605")) +d %>% mutate(name = match_area(code)) ``` ### postcode -```{r postcode, message = FALSE, warning = FALSE} +```{r postcode, warning = FALSE} # The default is pc7 format postcode("G26QE") @@ -87,49 +129,50 @@ postcode("G26QE") postcode(c("KA89NB", "PA152TY"), format = "pc8") # postcode accounts for irregular spacing and lower case letters -library(dplyr) -b <- tibble(pc = c("G 4 2 9 B A", "g207al", "Dg98bS", "DD37J y")) -b %>% mutate(pc = postcode(pc)) +e <- tibble(pc = c("G 4 2 9 B A", "g207al", "Dg98bS", "DD37J y")) +e %>% mutate(pc = postcode(pc)) ``` ### qtr, qtr_end, qtr_next and qtr_prev ```{r qtr} -c <- lubridate::dmy(c(26032012, 04052012, 23092012)) +f <- lubridate::dmy(c(26032012, 04052012, 23092012)) # qtr returns the current quarter and year # The default is long format -qtr(c) +qtr(f) # But short format can also be applied -qtr(c, format = "short") +qtr(f, format = "short") # qtr_end returns the last month in the quarter -qtr_end(c) -qtr_end(c, format = "short") +qtr_end(f) +qtr_end(f, format = "short") # qtr_next returns the next quarter -qtr_next(c) -qtr_next(c, format = "short") +qtr_next(f) +qtr_next(f, format = "short") # qtr_prev returns the previous quarter -qtr_prev(c) -qtr_prev(c, format = "short") +qtr_prev(f) +qtr_prev(f, format = "short") ``` ## Contributing to phsmethods -At present, the maintainers of this package are [Jack Hannah](https://github.com/jackhannah95), [David Caldwell](https://github.com/davidc92) and [Lucinda Lawrie](https://github.com/lucindalawrie). +At present, the maintainers of this package are [David Caldwell](https://github.com/davidc92) and [Lucinda Lawrie](https://github.com/lucindalawrie). + +This package is intended to be in continuous development and contributions may be made by anyone within PHS. If you would like to make a contribution, please first create an [issue](https://github.com/Health-SocialCare-Scotland/phsmethods/issues) on GitHub and assign **both** of the package maintainers to it. This is to ensure that no duplication of effort occurs in the case of multiple people having the same idea. The package maintainers will discuss the issue and get back to you as soon as possible. -This package is intended to be in continuous development and contributions may be made by anyone within PHS. If you would like to contribute a function, or propose an improvement to an existing function, please first create an [issue](https://github.com/Health-SocialCare-Scotland/phsmethods/issues) on GitHub and assign **all** of the package maintainers to it. This is to ensure that no duplication of effort occurs in the case of multiple people having the same idea. The package maintainers will discuss the issue and get back to you as soon as possible. +While the most obvious and eyecatching (as well as intimidating) way of contributing is by writing a function, this isn't the only way to make a useful contribution. Fixing typos in documentation, for example, isn't the most glamorous way to contribute, but is of great help to the package maintainers. Please see this [blogpost by Jim Hester](https://www.tidyverse.org/blog/2017/08/contributing/) for more information on getting started with contributing to open source software. -When contributing, please create a [branch](https://github.com/Health-SocialCare-Scotland/phsmethods/branches) in this repository and carry out all work on it. Please ensure you have linked RStudio to your GitHub account using `usethis::edit_git_config()` prior to making your contribution. When you are ready for a review, please create a [pull request](https://github.com/Health-SocialCare-Scotland/phsmethods/pulls) and assign **all** of the package maintainers as reviewers. One or more of them will conduct a review, provide feedback and, if necessary, request changes prior to merging your branch. +When contributing, please create a [branch](https://github.com/Health-SocialCare-Scotland/phsmethods/branches) in this repository and carry out all work on it. Please ensure you have linked RStudio to your GitHub account using `usethis::edit_git_config()` prior to making your contribution. When you are ready for a review, please create a [pull request](https://github.com/Health-SocialCare-Scotland/phsmethods/pulls) and assign **both** of the package maintainers as reviewers. One or both of them will conduct a review, provide feedback and, if necessary, request changes prior to merging your branch. Please be mindful of information governance when contributing to this package. No data files (aside from publicly available and downloadable datasets or unless explicitly approved), server connection details, passwords or person identifiable or otherwise confidential information should be included anywhere within this package or any other repository (whether public or private) used within PHS. This includes within code and code commentary. For more information on security when using git and GitHub, and on using git and GitHub for version control more generally, please see the [Transforming Publishing Programme](https://www.isdscotland.org/Products-and-Services/Transforming-Publishing-Programme/)'s [Git guide](https://nhs-nss-transforming-publications.github.io/git-guide/) and [GitHub guidance](https://github.com/NHS-NSS-transforming-publications/GitHub-guidance). -Please feel free to add yourself to the 'Authors' section of the `Description` file when contributing. As a rule of thumb, please assign your role as author (`"aut"`) when writing an exported function, and as contributor (`"ctb"`) when editing an existing function and/or writing a non-exported function. +Please feel free to add yourself to the 'Authors' section of the `Description` file when contributing. As a rule of thumb, please assign your role as author (`"aut"`) when writing an exported function, and as contributor (`"ctb"`) for anything else. `phsmethods` will, as much as possible, adhere to the [tidyverse style guide](https://style.tidyverse.org/) and the [rOpenSci package development guide](https://devguide.ropensci.org/). The most pertinent points to take from these are: @@ -141,6 +184,6 @@ Please feel free to add yourself to the 'Authors' section of the `Description` f - All functions should be tested using [`testthat`](https://github.com/r-lib/testthat) - The package should always pass `devtools::check()` -It's not necessary to have experience with GitHub or of building an R package to contribute to `phsmethods`; as long as you can write an R function, the package maintainers can assist with error handling, writing documentation, testing and other aspects of package development. It is advised, however, to consult Hadley Wickham's [R Packages](https://r-pkgs.org/) book prior to making a contribution. It may also be useful to consult the [documentation](https://github.com/Health-SocialCare-Scotland/phsmethods/tree/master/R) and [tests](https://github.com/Health-SocialCare-Scotland/phsmethods/tree/master/tests/testthat) of existing functions within this package as a point of reference. +It's not necessary to have experience with GitHub or of building an R package to contribute to `phsmethods`. If you wish to contribute code then, as long as you can write an R function, the package maintainers can assist with error handling, writing documentation, testing and other aspects of package development. It is advised, however, to consult [Hadley Wickham's R Packages book](https://r-pkgs.org/) prior to making a contribution. It may also be useful to consult the [documentation](https://github.com/Health-SocialCare-Scotland/phsmethods/tree/master/R) and [tests](https://github.com/Health-SocialCare-Scotland/phsmethods/tree/master/tests/testthat) of existing functions within this package as a point of reference. -Please note that this README may fail to 'Knit' at times as a result of network security settings. This will likely be due to the badges for continuous integration and test coverage at the top of the document. If you are editing the `README.Rmd` document and are unable to successfully get it to 'Knit', please contact the package maintainers for assistance. +Please note that this README may fail to 'Knit' at times as a result of network security settings. This will likely be due to the badges for the package's release version, continuous integration status and test coverage at the top of the document. If you are editing the `README.Rmd` document and are unable to successfully get it to 'Knit', please contact the package maintainers for assistance. diff --git a/README.md b/README.md index ba44871..50331db 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,13 @@ Status](https://travis-ci.com/Health-SocialCare-Scotland/phsmethods.svg?branch=m in [Public Health Scotland (PHS)](https://www.publichealthscotland.scot/): + - `age_group()` categorises ages into groups + - `chi_check()` assesses the validity of a CHI number + - `chi_pad()` adds a leading zero to nine-digit CHI numbers - `file_size()` returns the names and sizes of files in a directory - `fin_year()` assigns a date to a financial year in the format `YYYY/YY` + - `match_area()` converts geography codes into area names - `postcode()` formats improperly recorded postcodes - `qtr()`, `qtr_end()`, `qtr_next()` and `qtr_prev()` assign a date to a quarter @@ -64,6 +68,45 @@ To access the help file for any of `phsmethods`’ functions, type ?postcode ``` +### age\_group + +``` r +a <- c(54, 7, 77, 1, 26, 101) + +# By default age_group goes in 5 year increments from 0 to 90+ +age_group(a) +#> [1] "50-54" "5-9" "75-79" "0-4" "25-29" "90+" + +# But these settings can be changed +age_group(a, from = 0, to = 80, by = 10) +#> [1] "50-59" "0-9" "70-79" "0-9" "20-29" "80+" +``` + +### chi\_check + +``` r +# chi_check returns specific feedback on why a CHI number might be invalid +library(dplyr) +b <- tibble(chi = c("0101011237", "3213201234", "123456789", "12345678900", "010120123?")) +b %>% mutate(validity = chi_check(chi)) +#> # A tibble: 5 x 2 +#> chi validity +#> +#> 1 0101011237 Valid CHI +#> 2 3213201234 Invalid date +#> 3 123456789 Too few characters +#> 4 12345678900 Too many characters +#> 5 010120123? Invalid character(s) present +``` + +### chi\_pad + +``` r +# Only nine-digit characters are prefixed with a zero +chi_pad(c("101011237", "101201234", "123223")) +#> [1] "0101011237" "0101201234" "123223" +``` + ### file\_size ``` r @@ -82,7 +125,7 @@ file_size(testthat::test_path("files")) #> 8 swiss.tsv TSV 1 KB # Names and sizes of Excel files only in the tests/testthat/files folder -file_size(testthat::test_path("files"), pattern = ".xlsx?$") +file_size(testthat::test_path("files"), pattern = "\\.xlsx?$") #> # A tibble: 2 x 2 #> name size #> @@ -93,11 +136,29 @@ file_size(testthat::test_path("files"), pattern = ".xlsx?$") ### fin\_year ``` r -a <- lubridate::dmy(c(21012017, 04042017, 17112017)) -fin_year(a) +c <- lubridate::dmy(c(21012017, 04042017, 17112017)) +fin_year(c) #> [1] "2016/17" "2017/18" "2017/18" ``` +### match\_area + +``` r +match_area("S13002781") +#> [1] "Ayr North" + +d <- tibble(code = c("S02000656", "S02001042", "S08000020", "S12000013", "S13002605")) +d %>% mutate(name = match_area(code)) +#> # A tibble: 5 x 2 +#> code name +#> +#> 1 S02000656 Govan and Linthouse +#> 2 S02001042 Peebles North +#> 3 S08000020 Grampian +#> 4 S12000013 Na h-Eileanan Siar +#> 5 S13002605 Steòrnabhagh a Deas +``` + ### postcode ``` r @@ -110,9 +171,8 @@ postcode(c("KA89NB", "PA152TY"), format = "pc8") #> [1] "KA8 9NB" "PA15 2TY" # postcode accounts for irregular spacing and lower case letters -library(dplyr) -b <- tibble(pc = c("G 4 2 9 B A", "g207al", "Dg98bS", "DD37J y")) -b %>% mutate(pc = postcode(pc)) +e <- tibble(pc = c("G 4 2 9 B A", "g207al", "Dg98bS", "DD37J y")) +e %>% mutate(pc = postcode(pc)) #> # A tibble: 4 x 1 #> pc #> @@ -125,58 +185,65 @@ b %>% mutate(pc = postcode(pc)) ### qtr, qtr\_end, qtr\_next and qtr\_prev ``` r -c <- lubridate::dmy(c(26032012, 04052012, 23092012)) +f <- lubridate::dmy(c(26032012, 04052012, 23092012)) # qtr returns the current quarter and year # The default is long format -qtr(c) +qtr(f) #> [1] "January to March 2012" "April to June 2012" "July to September 2012" # But short format can also be applied -qtr(c, format = "short") +qtr(f, format = "short") #> [1] "Jan-Mar 2012" "Apr-Jun 2012" "Jul-Sep 2012" # qtr_end returns the last month in the quarter -qtr_end(c) +qtr_end(f) #> [1] "March 2012" "June 2012" "September 2012" -qtr_end(c, format = "short") +qtr_end(f, format = "short") #> [1] "Mar 2012" "Jun 2012" "Sep 2012" # qtr_next returns the next quarter -qtr_next(c) +qtr_next(f) #> [1] "April to June 2012" "July to September 2012" #> [3] "October to December 2012" -qtr_next(c, format = "short") +qtr_next(f, format = "short") #> [1] "Apr-Jun 2012" "Jul-Sep 2012" "Oct-Dec 2012" # qtr_prev returns the previous quarter -qtr_prev(c) +qtr_prev(f) #> [1] "October to December 2011" "January to March 2012" #> [3] "April to June 2012" -qtr_prev(c, format = "short") +qtr_prev(f, format = "short") #> [1] "Oct-Dec 2011" "Jan-Mar 2012" "Apr-Jun 2012" ``` ## Contributing to phsmethods -At present, the maintainers of this package are [Jack -Hannah](https://github.com/jackhannah95), [David +At present, the maintainers of this package are [David Caldwell](https://github.com/davidc92) and [Lucinda Lawrie](https://github.com/lucindalawrie). This package is intended to be in continuous development and contributions may be made by anyone within PHS. If you would like to -contribute a function, or propose an improvement to an existing -function, please first create an +make a contribution, please first create an [issue](https://github.com/Health-SocialCare-Scotland/phsmethods/issues) -on GitHub and assign **all** of the package maintainers to it. This is +on GitHub and assign **both** of the package maintainers to it. This is to ensure that no duplication of effort occurs in the case of multiple people having the same idea. The package maintainers will discuss the issue and get back to you as soon as possible. +While the most obvious and eyecatching (as well as intimidating) way of +contributing is by writing a function, this isn’t the only way to make a +useful contribution. Fixing typos in documentation, for example, isn’t +the most glamorous way to contribute, but is of great help to the +package maintainers. Please see this [blogpost by Jim +Hester](https://www.tidyverse.org/blog/2017/08/contributing/) for more +information on getting started with contributing to open source +software. + When contributing, please create a [branch](https://github.com/Health-SocialCare-Scotland/phsmethods/branches) in this repository and carry out all work on it. Please ensure you have @@ -184,7 +251,7 @@ linked RStudio to your GitHub account using `usethis::edit_git_config()` prior to making your contribution. When you are ready for a review, please create a [pull request](https://github.com/Health-SocialCare-Scotland/phsmethods/pulls) -and assign **all** of the package maintainers as reviewers. One or more +and assign **both** of the package maintainers as reviewers. One or both of them will conduct a review, provide feedback and, if necessary, request changes prior to merging your branch. @@ -206,8 +273,7 @@ guidance](https://github.com/NHS-NSS-transforming-publications/GitHub-guidance). Please feel free to add yourself to the ‘Authors’ section of the `Description` file when contributing. As a rule of thumb, please assign your role as author (`"aut"`) when writing an exported function, and as -contributor (`"ctb"`) when editing an existing function and/or writing a -non-exported function. +contributor (`"ctb"`) for anything else. `phsmethods` will, as much as possible, adhere to the [tidyverse style guide](https://style.tidyverse.org/) and the [rOpenSci package @@ -227,19 +293,20 @@ points to take from these are: - The package should always pass `devtools::check()` It’s not necessary to have experience with GitHub or of building an R -package to contribute to `phsmethods`; as long as you can write an R -function, the package maintainers can assist with error handling, -writing documentation, testing and other aspects of package development. -It is advised, however, to consult Hadley Wickham’s [R -Packages](https://r-pkgs.org/) book prior to making a contribution. It -may also be useful to consult the +package to contribute to `phsmethods`. If you wish to contribute code +then, as long as you can write an R function, the package maintainers +can assist with error handling, writing documentation, testing and other +aspects of package development. It is advised, however, to consult +[Hadley Wickham’s R Packages book](https://r-pkgs.org/) prior to making +a contribution. It may also be useful to consult the [documentation](https://github.com/Health-SocialCare-Scotland/phsmethods/tree/master/R) and [tests](https://github.com/Health-SocialCare-Scotland/phsmethods/tree/master/tests/testthat) of existing functions within this package as a point of reference. Please note that this README may fail to ‘Knit’ at times as a result of -network security settings. This will likely be due to the badges for -continuous integration and test coverage at the top of the document. If -you are editing the `README.Rmd` document and are unable to successfully -get it to ‘Knit’, please contact the package maintainers for assistance. +network security settings. This will likely be due to the badges for the +package’s release version, continuous integration status and test +coverage at the top of the document. If you are editing the `README.Rmd` +document and are unable to successfully get it to ‘Knit’, please contact +the package maintainers for assistance. diff --git a/data-raw/area_lookup.R b/data-raw/area_lookup.R index 9bb5786..a574546 100644 --- a/data-raw/area_lookup.R +++ b/data-raw/area_lookup.R @@ -1,17 +1,17 @@ ### This script downloads and formats data pertaining to geographic area names -### and codes from the Scottish Government open data platform. +### and codes from the Scottish Government open data platform ### ### The resulting file is used inside the match_area function and is made -### available to users of the package via phsmethods::area_lookup. +### available to users of the package via phsmethods::area_lookup ### ### This script should be re-run prior to every package release, to ensure the -### most up-to-date information provided by the Scottish Government is used. +### most up-to-date information provided by the Scottish Government is used ### ### Any substantial changes to the data should be noted in the section -### pertaining to the latest release in the NEWS.md file. +### pertaining to the latest release in the NEWS.md file ### -### This code should run successfully on RStudio server. -### It may time out on RStudio desktop due to network security settings. +### This code should run successfully on RStudio server +### It may time out on RStudio desktop due to network security settings library(SPARQL) diff --git a/man/age_group.Rd b/man/age_group.Rd index 21d360c..20f3b65 100644 --- a/man/age_group.Rd +++ b/man/age_group.Rd @@ -20,12 +20,12 @@ age_group(x, from = 0, to = 90, by = 5, as_factor = FALSE) } \value{ A character vector, where each element is the age group for the - corresponding element in \code{x}. If \code{as_factor = TRUE} a factor - vector is returned instead. +corresponding element in \code{x}. If \code{as_factor = TRUE}, a factor +vector is returned instead. } \description{ -age_group() takes a numeric vector and assigns each age to the appropriate -age group. +\code{age_group()} takes a numeric vector and assigns each age to the +appropriate age group. } \details{ The \code{from}, \code{to} and \code{by} values are used to create distinct diff --git a/man/qtr.Rd b/man/qtr.Rd index 6c4a81a..a720f3f 100644 --- a/man/qtr.Rd +++ b/man/qtr.Rd @@ -28,13 +28,13 @@ quarter-related value from it. They all return the year as part of this value. \itemize{ -\item \code{qtr} returns the current quarter. +\item \code{qtr} returns the current quarter -\item \code{qtr_end} returns the last month in the quarter. +\item \code{qtr_end} returns the last month in the quarter -\item \code{qtr_next} returns the next quarter. +\item \code{qtr_next} returns the next quarter -\item \code{qtr_prev} returns the previous quarter. +\item \code{qtr_prev} returns the previous quarter } } \details{ diff --git a/tests/testthat/test-age_group.R b/tests/testthat/test-age_group.R index 56e8ecf..ce5e5e3 100644 --- a/tests/testthat/test-age_group.R +++ b/tests/testthat/test-age_group.R @@ -12,7 +12,7 @@ test_that("Return correct age groups", { 0, 90, 5, as_factor = TRUE), factor(c("5-9", "90+", "40-44", "55-59", "10-14"), - levels = c("0-4", "5-9", "10-14", "15-19","20-24", "25-29", "30-34", + levels = c("0-4", "5-9", "10-14", "15-19", "20-24", "25-29", "30-34", "35-39", "40-44", "45-49", "50-54", "55-59", "60-64", "65-69", "70-74", "75-79", "80-84", "85-89", "90+"), ordered = TRUE)) @@ -42,7 +42,8 @@ test_that("Default value for age groups", { test_that("Handling of non-numeric values for x", { - # If x is not numeric cut will error. + + # If x is not numeric cut will error expect_error(age_group(c("1", "57", "apple", "12"), as_factor = FALSE)) # This is true even if all elements are numbers stored as character diff --git a/tests/testthat/test-file_size.R b/tests/testthat/test-file_size.R index e051d6f..212df7c 100644 --- a/tests/testthat/test-file_size.R +++ b/tests/testthat/test-file_size.R @@ -26,7 +26,7 @@ test_that("Returns sizes in alphabetical order", { }) test_that("Errors if supplied with invalid filepath", { - expect_error(file_size(here::here("datatest"))) + expect_error(file_size(here::here("reference_files"))) expect_error(file_size(NA)) expect_error(file_size(NULL)) })