From 2a22965722210994183a871fee827334b3af3a25 Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Mon, 3 Feb 2020 13:27:14 +0000 Subject: [PATCH 01/22] Add POSIXct to error handling --- R/fin_year.R | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/R/fin_year.R b/R/fin_year.R index fd05340..dd4f237 100644 --- a/R/fin_year.R +++ b/R/fin_year.R @@ -17,14 +17,8 @@ #' @export fin_year <- function(date) { - if (!inherits(date, "Date")) { - stop("The input must have Date class.") + if (!inherits(date, c("Date", "POSIXct"))) { + stop("The input must have Date or POSIXct class.") } - paste0(ifelse(lubridate::month(date) >= 4, - lubridate::year(date), - lubridate::year(date) - 1), "/", - substr(ifelse(lubridate::month(date) >= 4, - lubridate::year(date) + 1, - lubridate::year(date)), 3, 4)) } From 07149bdd4d2807702fec8124e47b63a8d2a6c23f Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Mon, 3 Feb 2020 13:45:23 +0000 Subject: [PATCH 02/22] Update function --- R/fin_year.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/R/fin_year.R b/R/fin_year.R index dd4f237..852ca0c 100644 --- a/R/fin_year.R +++ b/R/fin_year.R @@ -21,4 +21,16 @@ fin_year <- function(date) { stop("The input must have Date or POSIXct class.") } + unique_dates <- tibble(dates = unique(date)) %>% + + mutate(fin_year = paste0(ifelse(lubridate::month(dates) >= 4, + lubridate::year(dates), + lubridate::year(dates) - 1), "/", + substr(ifelse(lubridate::month(dates) >= 4, + lubridate::year(dates) + 1, + lubridate::year(dates)), 3, 4))) %>% + right_join(tibble::tibble(dates = date)) + + unique_dates + } From 2886de3df7e8b2d7a34f39f1a1d75086dc662258 Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Mon, 3 Feb 2020 13:53:07 +0000 Subject: [PATCH 03/22] Return only vector of financial years --- R/fin_year.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/fin_year.R b/R/fin_year.R index 852ca0c..1c3294a 100644 --- a/R/fin_year.R +++ b/R/fin_year.R @@ -5,9 +5,9 @@ #' #' @details The PHS accepted format for financial year is yyyy/yy e.g. 2017/18. #' -#' @param date A date which must be supplied with \code{Date} class. The -#' functions as.Date() or lubridate::dmy() are examples of functions that can -#' be used to change a variable to date class. +#' @param date A date which must be supplied with \code{Date} or \code{POSIXct} +#' class. The functions as.Date() or lubridate::dmy() as.POSIXct() are examples +#' of functions that can be used to change a variable to the appropriate class. #' #' @examples #' x <- lubridate::dmy(c(21012017, 04042017, 17112017)) @@ -31,6 +31,6 @@ fin_year <- function(date) { lubridate::year(dates)), 3, 4))) %>% right_join(tibble::tibble(dates = date)) - unique_dates + unique_dates$dates } From 15c7a048fd9e5d59a57b5e11a235243ffaa8cd61 Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Mon, 3 Feb 2020 14:00:07 +0000 Subject: [PATCH 04/22] Add tibble:: to function call --- R/fin_year.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/fin_year.R b/R/fin_year.R index 1c3294a..6175569 100644 --- a/R/fin_year.R +++ b/R/fin_year.R @@ -21,7 +21,7 @@ fin_year <- function(date) { stop("The input must have Date or POSIXct class.") } - unique_dates <- tibble(dates = unique(date)) %>% + unique_dates <- tibble::tibble(dates = unique(date)) %>% mutate(fin_year = paste0(ifelse(lubridate::month(dates) >= 4, lubridate::year(dates), From 853de3e992852d666a785fc2e3f23953dba67f1f Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Mon, 3 Feb 2020 14:04:23 +0000 Subject: [PATCH 05/22] Add dplyr:: to function calls! --- R/fin_year.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/fin_year.R b/R/fin_year.R index 6175569..c11ee3b 100644 --- a/R/fin_year.R +++ b/R/fin_year.R @@ -23,13 +23,13 @@ fin_year <- function(date) { unique_dates <- tibble::tibble(dates = unique(date)) %>% - mutate(fin_year = paste0(ifelse(lubridate::month(dates) >= 4, + dplyr::mutate(fin_year = paste0(ifelse(lubridate::month(dates) >= 4, lubridate::year(dates), lubridate::year(dates) - 1), "/", substr(ifelse(lubridate::month(dates) >= 4, lubridate::year(dates) + 1, lubridate::year(dates)), 3, 4))) %>% - right_join(tibble::tibble(dates = date)) + dplyr::right_join(tibble::tibble(dates = date)) unique_dates$dates From c19d7a977ccee2f6e7021dc04c94c45dfb205e9b Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Mon, 3 Feb 2020 14:11:06 +0000 Subject: [PATCH 06/22] Fix error --- R/fin_year.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/fin_year.R b/R/fin_year.R index c11ee3b..8310ab4 100644 --- a/R/fin_year.R +++ b/R/fin_year.R @@ -31,6 +31,6 @@ fin_year <- function(date) { lubridate::year(dates)), 3, 4))) %>% dplyr::right_join(tibble::tibble(dates = date)) - unique_dates$dates + unique_dates$fin_year } From ac629cf1d56907f680107b0d470fcba11c2eeabc Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Mon, 3 Feb 2020 14:15:49 +0000 Subject: [PATCH 07/22] Update tests --- tests/testthat/test-fin_year.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test-fin_year.R b/tests/testthat/test-fin_year.R index 8af557e..c79af8c 100644 --- a/tests/testthat/test-fin_year.R +++ b/tests/testthat/test-fin_year.R @@ -3,12 +3,14 @@ context("test-fin_year") test_that("Date is assigned to the correct financial year", { expect_equal(fin_year(as.Date("20120331", "%Y%m%d")), "2011/12") expect_equal(fin_year(as.Date("20120401", "%Y%m%d")), "2012/13") + expect_equal(fin_year(as.POSIXct("20190104", format = "%Y%m%d")), "2018/19") }) test_that("Date is accepted in various formats", { expect_equal(fin_year(as.Date("17111993", "%d%m%Y")), "1993/94") expect_equal(fin_year(as.Date("19980404", "%Y%m%d")), "1998/99") expect_equal(fin_year(as.Date("21-Jan-2017", "%d-%B-%Y")), "2016/17") + expect_equal(fin_year(as.POSIXct("20181401", format = "%Y%d%m")), "2017/18") expect_equal(fin_year(lubridate::dmy(29102019)), "2019/20") }) From 48fa1cb93c10fbdab8ef9d3676327480e9ad8dd8 Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Mon, 3 Feb 2020 14:19:32 +0000 Subject: [PATCH 08/22] Update documentation --- man/fin_year.Rd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/man/fin_year.Rd b/man/fin_year.Rd index e16d76b..38f4623 100644 --- a/man/fin_year.Rd +++ b/man/fin_year.Rd @@ -7,9 +7,9 @@ fin_year(date) } \arguments{ -\item{date}{A date which must be supplied with \code{Date} class. The -functions as.Date() or lubridate::dmy() are examples of functions that can -be used to change a variable to date class.} +\item{date}{A date which must be supplied with \code{Date} or \code{POSIXct} +class. The functions as.Date() or lubridate::dmy() as.POSIXct() are examples +of functions that can be used to change a variable to the appropriate class.} } \description{ \code{fin_year} takes a date and assigns it to the correct From 1e553cdddee2ea2dfe15c929109186903b8fb22b Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Wed, 5 Feb 2020 11:41:10 +0000 Subject: [PATCH 09/22] Fix documentation --- R/fin_year.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/fin_year.R b/R/fin_year.R index 8310ab4..11b159c 100644 --- a/R/fin_year.R +++ b/R/fin_year.R @@ -6,7 +6,7 @@ #' @details The PHS accepted format for financial year is yyyy/yy e.g. 2017/18. #' #' @param date A date which must be supplied with \code{Date} or \code{POSIXct} -#' class. The functions as.Date() or lubridate::dmy() as.POSIXct() are examples +#' class. The functions as.Date(), lubridate::dmy() or as.POSIXct() are examples #' of functions that can be used to change a variable to the appropriate class. #' #' @examples From 47e915f85a4bf343a1d17afc74f9f57edd2516d0 Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Wed, 5 Feb 2020 15:23:11 +0000 Subject: [PATCH 10/22] Fix spacing --- R/fin_year.R | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/R/fin_year.R b/R/fin_year.R index 11b159c..5c45532 100644 --- a/R/fin_year.R +++ b/R/fin_year.R @@ -23,12 +23,13 @@ fin_year <- function(date) { unique_dates <- tibble::tibble(dates = unique(date)) %>% - dplyr::mutate(fin_year = paste0(ifelse(lubridate::month(dates) >= 4, - lubridate::year(dates), - lubridate::year(dates) - 1), "/", - substr(ifelse(lubridate::month(dates) >= 4, - lubridate::year(dates) + 1, - lubridate::year(dates)), 3, 4))) %>% + dplyr::mutate(fin_year = paste0(ifelse(lubridate::month(dates) >= 4, + lubridate::year(dates), + lubridate::year(dates) - 1), "/", + substr(ifelse(lubridate::month(dates) >= 4, + lubridate::year(dates) + 1, + lubridate::year(dates)), + 3, 4))) %>% dplyr::right_join(tibble::tibble(dates = date)) unique_dates$fin_year From 25b4d2f7d457932fbf9b314e9bdcb6ce472c7cf1 Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Wed, 5 Feb 2020 15:24:47 +0000 Subject: [PATCH 11/22] Make small tweaks --- R/fin_year.R | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/R/fin_year.R b/R/fin_year.R index 5c45532..26e47ec 100644 --- a/R/fin_year.R +++ b/R/fin_year.R @@ -30,8 +30,6 @@ fin_year <- function(date) { lubridate::year(dates) + 1, lubridate::year(dates)), 3, 4))) %>% - dplyr::right_join(tibble::tibble(dates = date)) - - unique_dates$fin_year - + dplyr::right_join(tibble::tibble(dates = date), by = dates) %>% + dplyr::pull(fin_year) } From 80ea19adbb28c68c26baab469fff12e07fd8fb85 Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Wed, 5 Feb 2020 15:27:59 +0000 Subject: [PATCH 12/22] Update spacing again --- R/fin_year.R | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/R/fin_year.R b/R/fin_year.R index 26e47ec..209822a 100644 --- a/R/fin_year.R +++ b/R/fin_year.R @@ -23,13 +23,15 @@ fin_year <- function(date) { unique_dates <- tibble::tibble(dates = unique(date)) %>% - dplyr::mutate(fin_year = paste0(ifelse(lubridate::month(dates) >= 4, - lubridate::year(dates), - lubridate::year(dates) - 1), "/", - substr(ifelse(lubridate::month(dates) >= 4, - lubridate::year(dates) + 1, - lubridate::year(dates)), - 3, 4))) %>% + dplyr::mutate(fin_year = paste0(ifelse(lubridate::month(.data$dates) >= 4, + lubridate::year(.data$dates), + lubridate::year(.data$dates) - 1), + "/", + substr( + ifelse(lubridate::month(.data$dates) >= 4, + lubridate::year(.data$dates) + 1, + lubridate::year(.data$dates)), + 3, 4))) %>% dplyr::right_join(tibble::tibble(dates = date), by = dates) %>% dplyr::pull(fin_year) } From 06d32db0f5de445bc3828598253d3733ba5325da Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Wed, 5 Feb 2020 15:29:40 +0000 Subject: [PATCH 13/22] add imports --- DESCRIPTION | 3 ++- R/phsmethods.R | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 11220a6..4b1a448 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,7 +21,8 @@ Imports: purrr, stringi, stringr, - tibble + tibble, + rlang Suggests: covr, here, diff --git a/R/phsmethods.R b/R/phsmethods.R index 85c3a03..50086d6 100644 --- a/R/phsmethods.R +++ b/R/phsmethods.R @@ -7,6 +7,7 @@ #' @docType package #' @name phsmethods #' @importFrom magrittr %>% +#' @importFrom rlang .data NULL # Stops notes from appearing in R CMD check because of undefined global From 9b109df5490e61ba61bfccdd9df127ed49136908 Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Wed, 5 Feb 2020 17:09:23 +0000 Subject: [PATCH 14/22] Fix typo --- R/fin_year.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/fin_year.R b/R/fin_year.R index 209822a..74f0dc1 100644 --- a/R/fin_year.R +++ b/R/fin_year.R @@ -32,6 +32,6 @@ fin_year <- function(date) { lubridate::year(.data$dates) + 1, lubridate::year(.data$dates)), 3, 4))) %>% - dplyr::right_join(tibble::tibble(dates = date), by = dates) %>% + dplyr::right_join(tibble::tibble(dates = date), by = "dates") %>% dplyr::pull(fin_year) } From bf010b8b9ab2656abe1555af113e5ee9d404b7b2 Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Wed, 5 Feb 2020 17:10:21 +0000 Subject: [PATCH 15/22] Make imports alphabetical --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4b1a448..b869148 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,10 +19,10 @@ Imports: lubridate, magrittr, purrr, + rlang, stringi, stringr, - tibble, - rlang + tibble Suggests: covr, here, From 34f9ff50aa4184f258437f3f42c8af14b6e978ab Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Thu, 6 Feb 2020 09:34:41 +0000 Subject: [PATCH 16/22] Add a note explaining methodology --- R/fin_year.R | 6 ++++++ man/fin_year.Rd | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/R/fin_year.R b/R/fin_year.R index 74f0dc1..7f99112 100644 --- a/R/fin_year.R +++ b/R/fin_year.R @@ -21,6 +21,12 @@ fin_year <- function(date) { stop("The input must have Date or POSIXct class.") } + # Simply converting all elements of the input vector resulted in poor + # performance for large vectors. The function was rewritten to extract + # a vector of unique elements from the input, convert those to financial year + # and then match them back on to the original input. This vastly improves + # performance for large inputs + unique_dates <- tibble::tibble(dates = unique(date)) %>% dplyr::mutate(fin_year = paste0(ifelse(lubridate::month(.data$dates) >= 4, diff --git a/man/fin_year.Rd b/man/fin_year.Rd index 38f4623..15e5f9f 100644 --- a/man/fin_year.Rd +++ b/man/fin_year.Rd @@ -8,7 +8,7 @@ fin_year(date) } \arguments{ \item{date}{A date which must be supplied with \code{Date} or \code{POSIXct} -class. The functions as.Date() or lubridate::dmy() as.POSIXct() are examples +class. The functions as.Date(), lubridate::dmy() or as.POSIXct() are examples of functions that can be used to change a variable to the appropriate class.} } \description{ From e20699b8f12815e3597fb4d2980fed70db19ab68 Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Thu, 6 Feb 2020 10:53:45 +0000 Subject: [PATCH 17/22] Add line to news! --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index a8aa2ae..b4709ad 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,5 @@ # 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). +- `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). The performance of `fin_year()` has been improved by adjusting the methodology to generate a vector of financial years from the unique elements of the input vector and matching them back to the original list. # phsmethods 0.1.0 (2020-01-24) From c34ff69e4951ede956565ed92eaf6dc2fb6eba23 Mon Sep 17 00:00:00 2001 From: David Caldwell Date: Thu, 6 Feb 2020 10:55:44 +0000 Subject: [PATCH 18/22] Update namespace --- NAMESPACE | 1 + 1 file changed, 1 insertion(+) diff --git a/NAMESPACE b/NAMESPACE index a9e361f..1eb4fbc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,3 +8,4 @@ export(qtr_end) export(qtr_next) export(qtr_prev) importFrom(magrittr,"%>%") +importFrom(rlang,.data) From 8eb590fb7414cdfd2b08e855ad6cf81503370e91 Mon Sep 17 00:00:00 2001 From: jackhannah95 Date: Mon, 10 Feb 2020 11:26:31 +0000 Subject: [PATCH 19/22] return the value --- R/fin_year.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/fin_year.R b/R/fin_year.R index 7f99112..2376577 100644 --- a/R/fin_year.R +++ b/R/fin_year.R @@ -25,10 +25,9 @@ fin_year <- function(date) { # performance for large vectors. The function was rewritten to extract # a vector of unique elements from the input, convert those to financial year # and then match them back on to the original input. This vastly improves - # performance for large inputs - - unique_dates <- tibble::tibble(dates = unique(date)) %>% + # performance for large inputs. + tibble::tibble(dates = unique(date)) %>% dplyr::mutate(fin_year = paste0(ifelse(lubridate::month(.data$dates) >= 4, lubridate::year(.data$dates), lubridate::year(.data$dates) - 1), From 5cfa2a496c072f9b0d662500bd53faf14c59cfbc Mon Sep 17 00:00:00 2001 From: jackhannah95 Date: Mon, 10 Feb 2020 11:27:00 +0000 Subject: [PATCH 20/22] add PHS website link --- README.Rmd | 4 +- README.md | 157 ++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 117 insertions(+), 44 deletions(-) diff --git a/README.Rmd b/README.Rmd index 91d2a75..7ededcd 100644 --- a/README.Rmd +++ b/README.Rmd @@ -14,10 +14,12 @@ knitr::opts_chunk$set( # phsmethods +[![GitHub release (latest by +date)](https://img.shields.io/github/v/release/Health-SocialCare-Scotland/phsmethods)](https://github.com/Health-SocialCare-Scotland/phsmethods/releases/latest) [![Build Status](https://travis-ci.com/Health-SocialCare-Scotland/phsmethods.svg?branch=master)](https://travis-ci.com/Health-SocialCare-Scotland/phsmethods) [![codecov](https://codecov.io/gh/Health-SocialCare-Scotland/phsmethods/branch/master/graph/badge.svg)](https://codecov.io/gh/Health-SocialCare-Scotland/phsmethods) -`phsmethods` contains functions for commonly undertaken analytical tasks in [Public Health Scotland (PHS)](https://publichealthreform.scot/public-health-scotland): +`phsmethods` contains functions for commonly undertaken analytical tasks in [Public Health Scotland (PHS)](https://www.publichealthscotland.scot/): - `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` diff --git a/README.md b/README.md index f0adece..49d5588 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,33 @@ -phsmethods -========== -[![Build Status](https://travis-ci.com/Health-SocialCare-Scotland/phsmethods.svg?branch=master)](https://travis-ci.com/Health-SocialCare-Scotland/phsmethods) [![codecov](https://codecov.io/gh/Health-SocialCare-Scotland/phsmethods/branch/master/graph/badge.svg)](https://codecov.io/gh/Health-SocialCare-Scotland/phsmethods) +# phsmethods -`phsmethods` contains functions for commonly undertaken analytical tasks in [Public Health Scotland (PHS)](https://publichealthreform.scot/public-health-scotland): +[![GitHub release (latest by +date)](https://img.shields.io/github/v/release/Health-SocialCare-Scotland/phsmethods)](https://github.com/Health-SocialCare-Scotland/phsmethods/releases/latest) +[![Build +Status](https://travis-ci.com/Health-SocialCare-Scotland/phsmethods.svg?branch=master)](https://travis-ci.com/Health-SocialCare-Scotland/phsmethods) +[![codecov](https://codecov.io/gh/Health-SocialCare-Scotland/phsmethods/branch/master/graph/badge.svg)](https://codecov.io/gh/Health-SocialCare-Scotland/phsmethods) -- `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` -- `postcode()` formats improperly recorded postcodes -- `qtr()`, `qtr_end()`, `qtr_next()` and `qtr_prev()` assign a date to a quarter +`phsmethods` contains functions for commonly undertaken analytical tasks +in [Public Health Scotland +(PHS)](https://www.publichealthscotland.scot/): -`phsmethods` can be used on both the [server](https://rstudio.nhsnss.scot.nhs.uk/) and desktop versions of RStudio. + - `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` + - `postcode()` formats improperly recorded postcodes + - `qtr()`, `qtr_end()`, `qtr_next()` and `qtr_prev()` assign a date to + a quarter -Installation ------------- +`phsmethods` can be used on both the +[server](https://rstudio.nhsnss.scot.nhs.uk/) and desktop versions of +RStudio. -To install `phsmethods`, the package `remotes` is required, and can be installed with `install.packages("remotes")`. +## Installation + +To install `phsmethods`, the package `remotes` is required, and can be +installed with `install.packages("remotes")`. You can then install `phsmethods` on RStudio server from GitHub with: @@ -26,15 +36,19 @@ remotes::install_github("Health-SocialCare-Scotland/phsmethods", upgrade = "never") ``` -Network security settings may prevent `remotes::install_github()` from working on RStudio desktop. If this is the case, `phsmethods` can be installed by downloading the [zip of the repository](https://github.com/Health-SocialCare-Scotland/phsmethods/archive/master.zip) and running the following code (replacing the section marked `<>`, including the arrows themselves): +Network security settings may prevent `remotes::install_github()` from +working on RStudio desktop. If this is the case, `phsmethods` can be +installed by downloading the [zip of the +repository](https://github.com/Health-SocialCare-Scotland/phsmethods/archive/master.zip) +and running the following code (replacing the section marked `<>`, +including the arrows themselves): ``` r remotes::install_local("/phsmethods-master.zip", upgrade = "never") ``` -Using phsmethods ----------------- +## Using phsmethods Load `phsmethods` using `library()`: @@ -42,7 +56,8 @@ Load `phsmethods` using `library()`: library(phsmethods) ``` -To access the help file for any of `phsmethods`' functions, type `?function_name` into the RStudio console after loading the package: +To access the help file for any of `phsmethods`’ functions, type +`?function_name` into the RStudio console after loading the package: ``` r ?fin_year @@ -80,7 +95,6 @@ file_size(testthat::test_path("files"), pattern = ".xlsx?$") ``` r a <- lubridate::dmy(c(21012017, 04042017, 17112017)) fin_year(a) -#> [1] "2016/17" "2017/18" "2017/18" ``` ### postcode @@ -145,29 +159,86 @@ qtr_prev(c, 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 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 [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. - -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 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. - -`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: - -- All function names should be in lower case, with words separated by an underscore -- Put a space after a comma, never before -- Put a space before and after infix operators such as `<-`, `==` and `+` -- Limit code to 80 characters per line -- Function documentation should be generated using [`roxygen2`](https://github.com/r-lib/roxygen2) -- 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. - -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. +## 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). + +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. + +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 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. + +`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: + + - All function names should be in lower case, with words separated by + an underscore + - Put a space after a comma, never before + - Put a space before and after infix operators such as `<-`, `==` and + `+` + - Limit code to 80 characters per line + - Function documentation should be generated using + [`roxygen2`](https://github.com/r-lib/roxygen2) + - 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. + +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. From 35c415c1a9e12a3c40a12b0a35ac51ce1775dcd7 Mon Sep 17 00:00:00 2001 From: jackhannah95 Date: Mon, 10 Feb 2020 11:27:15 +0000 Subject: [PATCH 21/22] 0.1.1 release --- NEWS.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index b4709ad..d2be6d6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ -# 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). The performance of `fin_year()` has been improved by adjusting the methodology to generate a vector of financial years from the unique elements of the input vector and matching them back to the original list. +# 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). + +- The performance of `fin_year()` has been improved. The function now extracts the unique date(s) from the input, calculates the associated financial year(s), and joins to the original input. This is in contrast with the original method, which directly calculated the financial year of all input dates individually. # phsmethods 0.1.0 (2020-01-24) From 17aa98a090177897041813eebc43f36f9765bbda Mon Sep 17 00:00:00 2001 From: jackhannah95 Date: Mon, 10 Feb 2020 11:29:27 +0000 Subject: [PATCH 22/22] fix hyperlink --- README.Rmd | 3 +-- README.md | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.Rmd b/README.Rmd index 7ededcd..a2a92f0 100644 --- a/README.Rmd +++ b/README.Rmd @@ -14,8 +14,7 @@ knitr::opts_chunk$set( # phsmethods -[![GitHub release (latest by -date)](https://img.shields.io/github/v/release/Health-SocialCare-Scotland/phsmethods)](https://github.com/Health-SocialCare-Scotland/phsmethods/releases/latest) +[![GitHub release (latest by date)](https://img.shields.io/github/v/release/Health-SocialCare-Scotland/phsmethods)](https://github.com/Health-SocialCare-Scotland/phsmethods/releases/latest) [![Build Status](https://travis-ci.com/Health-SocialCare-Scotland/phsmethods.svg?branch=master)](https://travis-ci.com/Health-SocialCare-Scotland/phsmethods) [![codecov](https://codecov.io/gh/Health-SocialCare-Scotland/phsmethods/branch/master/graph/badge.svg)](https://codecov.io/gh/Health-SocialCare-Scotland/phsmethods) diff --git a/README.md b/README.md index 49d5588..ba44871 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ file_size(testthat::test_path("files"), pattern = ".xlsx?$") ``` r a <- lubridate::dmy(c(21012017, 04042017, 17112017)) fin_year(a) +#> [1] "2016/17" "2017/18" "2017/18" ``` ### postcode