Skip to content

Commit

Permalink
Merge branch 'master' into Add-release-badge
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhannah95 authored Feb 5, 2020
2 parents d257881 + 35c5b50 commit bd9602f
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 23 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: phsmethods
Title: Standard Methods for use in Public Health Scotland
Version: 0.1.0
Version: 0.1.1
Authors@R: c(
person("Jack", "Hannah", email = "[email protected]", role = c("aut", "cre")),
person("David", "Caldwell", email = "[email protected]", role = c("aut", "rev")),
Expand Down
9 changes: 6 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# phsmethods 0.1.0
# phsmethods 0.1.1 (2020-01-29)
- `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).

- Initial package release
- `file_size`, `fin_year`, `postcode`, `qtr`, `qtr_end`, `qtr_next` and `qtr_prev` functions added
# phsmethods 0.1.0 (2020-01-24)

- Initial package release.
- `file_size()`, `fin_year()`, `postcode()`, `qtr()`, `qtr_end()`, `qtr_next()` and `qtr_prev()` functions added.
4 changes: 2 additions & 2 deletions R/file_size.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ file_size <- function(filepath = getwd(), pattern = NULL) {
stop("A valid filepath must be supplied")
}

if (!class(pattern) %in% c("character", "NULL")) {
if (!inherits(pattern, c("character", "NULL"))) {
stop("A specified pattern must be of character class in order to be ",
"evaluated as a regular expression")
}

x <- dir(path = filepath, pattern = pattern)

if(length(x) == 0) {
if (length(x) == 0) {
return(NULL)
}

Expand Down
6 changes: 4 additions & 2 deletions R/fin_year.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
#' fin_year(x)
#'
#' @export
fin_year <- function(date){
if(class(date) != "Date"){
fin_year <- function(date) {

if (!inherits(date, "Date")) {
stop("The input must have Date class.")
}

paste0(ifelse(lubridate::month(date) >= 4,
lubridate::year(date),
lubridate::year(date) - 1), "/",
Expand Down
2 changes: 1 addition & 1 deletion R/phsmethods.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ NULL

# Stops notes from appearing in R CMD check because of undefined global
# variable '.'
if(getRversion() >= "2.15.1") utils::globalVariables(c("."))
if (getRversion() >= "2.15.1") utils::globalVariables(c("."))
11 changes: 6 additions & 5 deletions R/postcode.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ postcode <- function(string, format = c("pc7", "pc8")) {
singular <- "value does"
multiple <- "values do"

if(!all(
stringr::str_detect(
pc[!is.na(pc)],
"^[A-Za-z]{1,2}[0-9][A-Za-z0-9]?[0-9]{1}[A-Za-z]{2}$"))) {
if (
!all(
stringr::str_detect(
pc[!is.na(pc)],
"^[A-Za-z]{1,2}[0-9][A-Za-z0-9]?[0-9]{1}[A-Za-z]{2}$"))) {
warning(glue::glue("{n} non-NA input {ifelse(n == 1, singular, multiple)} ",
"not adhere to the standard UK postcode format (with ",
"or without spaces) and will be coded as NA. The ",
Expand All @@ -107,7 +108,7 @@ postcode <- function(string, format = c("pc7", "pc8")) {
"^[A-Za-z]{1,2}[0-9][A-Za-z0-9]?[0-9]{1}[A-Za-z]{2}$"),
NA_character_)

if(any(grepl("[a-z]", pc))) {
if (any(grepl("[a-z]", pc))) {
warning("Lower case letters in any input value(s) adhering to the ",
"standard UK postcode format will be converted to upper case")
}
Expand Down
20 changes: 12 additions & 8 deletions R/qtr.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ qtr <- function(date, format = c("long", "short")) {

format <- match.arg(format)

if (class(date) != "Date") {
stop("The input must have Date class")
if (!inherits(date, "Date")) {
stop("The input must have Date class.")
}

quarter_num <- lubridate::quarter(date)
Expand All @@ -64,6 +64,7 @@ qtr <- function(date, format = c("long", "short")) {
quarter_num == 4 ~ paste0("October to December ",
lubridate::year(date))))
} else {

return(dplyr::case_when(
quarter_num == 1 ~ paste0("Jan-Mar ",
lubridate::year(date)),
Expand All @@ -82,8 +83,8 @@ qtr_end <- function(date, format = c("long", "short")) {

format <- match.arg(format)

if (class(date) != "Date") {
stop("The input must have Date class")
if (!inherits(date, "Date")) {
stop("The input must have Date class.")
}

quarter_num <- lubridate::quarter(date)
Expand All @@ -99,6 +100,7 @@ qtr_end <- function(date, format = c("long", "short")) {
quarter_num == 4 ~ paste0("December ",
lubridate::year(date))))
} else {

return(dplyr::case_when(
quarter_num == 1 ~ paste0("Mar ",
lubridate::year(date)),
Expand All @@ -117,8 +119,8 @@ qtr_next <- function(date, format = c("long", "short")) {

format <- match.arg(format)

if (class(date) != "Date") {
stop("The input must have Date class")
if (!inherits(date, "Date")) {
stop("The input must have Date class.")
}

quarter_num <- lubridate::quarter(date)
Expand All @@ -134,6 +136,7 @@ qtr_next <- function(date, format = c("long", "short")) {
quarter_num == 4 ~ paste0("January to March ",
lubridate::year(date) + 1)))
} else {

return(dplyr::case_when(
quarter_num == 1 ~ paste0("Apr-Jun ",
lubridate::year(date)),
Expand All @@ -152,8 +155,8 @@ qtr_prev <- function(date, format = c("long", "short")) {

format <- match.arg(format)

if (class(date) != "Date") {
stop("The input must have Date class")
if (!inherits(date, "Date")) {
stop("The input must have Date class.")
}

quarter_num <- lubridate::quarter(date)
Expand All @@ -169,6 +172,7 @@ qtr_prev <- function(date, format = c("long", "short")) {
quarter_num == 4 ~ paste0("July to September ",
lubridate::year(date))))
} else {

return(dplyr::case_when(
quarter_num == 1 ~ paste0("Oct-Dec ",
lubridate::year(date) - 1),
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ This package is intended to be in continuous development and contributions may b

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.

Please be mindful of information governance when contributing to this package. No data files (aside from publically 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 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.

Expand Down

0 comments on commit bd9602f

Please sign in to comment.