diff --git a/.Rbuildignore b/.Rbuildignore index dcf6a31..0dcc9ba 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -5,3 +5,7 @@ ^CODE_OF_CONDUCT\.md$ README.Rmd cran-comments.md +^_pkgdown\.yml$ +^docs$ +^pkgdown$ +^\.github$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..ed7650c --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,48 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + release: + types: [published] + workflow_dispatch: + +name: pkgdown + +jobs: + pkgdown: + runs-on: ubuntu-latest + # Only restrict concurrency for non-PR jobs + concurrency: + group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::pkgdown, local::. + needs: website + + - name: Build site + run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) + shell: Rscript {0} + + - name: Deploy to GitHub pages 🚀 + if: github.event_name != 'pull_request' + uses: JamesIves/github-pages-deploy-action@v4.4.1 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/.gitignore b/.gitignore index 5a40bd3..54b8e1e 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,4 @@ po/*~ # RStudio Connect folder rsconnect/ inst/doc +docs diff --git a/DESCRIPTION b/DESCRIPTION index ce874b1..55b512a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,3 +21,4 @@ Suggests: knitr, rmarkdown VignetteBuilder: knitr +URL: https://nhs-r-community.github.io/NHSRwaitinglist/ diff --git a/NAMESPACE b/NAMESPACE index fbc2252..326692a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,7 +1,6 @@ # Generated by roxygen2: do not edit by hand export(average_wait) -export(example_function) export(queue_load) export(relief_capacity) export(target_capacity) diff --git a/R/example_function.R b/R/example_function.R deleted file mode 100644 index 779b8b9..0000000 --- a/R/example_function.R +++ /dev/null @@ -1,28 +0,0 @@ - -#' @title Example function for getting started -#' -#' @description This is an example function to help people getting involved. The function below takes two inputs, converts -#' them to characters and then concatenates them as a string for output. I've explicitly used the 'return' function at the end -#' , which is good practice, but the function will return the last row if not. Once you've written your function, if working in RStudio -#' , go to the 'Code' menu and select 'Insert Roxygen Skeleton', which will insert the metadata tags like this. Fill them in, and they -#' will be used to build the help files etc. -#' -#' @param input1 Something you want to put into the function, this could be a number, character etc. -#' @param input2 Something you want to put into the function, this could be a number, character etc. -#' -#' @return a character string of both inputs -#' @export -#' -#' @examples -#' example_function("something", 1234) -#' -example_function <- function(input1, input2){ - - input1 <- as.character(input1) - input2 <- as.character(input2) - - output <- paste(input1,",", input2) - - return(output) - -} diff --git a/_pkgdown.yml b/_pkgdown.yml new file mode 100644 index 0000000..b942a2a --- /dev/null +++ b/_pkgdown.yml @@ -0,0 +1,4 @@ +url: https://nhs-r-community.github.io/NHSRwaitinglist/ +template: + bootstrap: 5 + diff --git a/man/average_wait.Rd b/man/average_wait.Rd new file mode 100644 index 0000000..c92fd3a --- /dev/null +++ b/man/average_wait.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/average_wait.R +\name{average_wait} +\alias{average_wait} +\title{Average Waiting Time} +\usage{ +average_wait(target_wait, factor = 4) +} +\arguments{ +\item{target_wait}{Numeric value of the number of weeks that has been set as the target within which the patient should be seen.} + +\item{factor}{Numeric factor used in average wait calculation - to get a quarter of the target use factor=4 and one sixth of the target use factor = 6 etc. Defaults to 4.} +} +\value{ +Numeric value of target mean waiting time to achieve a given target wait. +} +\description{ +This calculates the target mean wait given the two inputs of target_wait and a numerical value for factor +The average wait is actually the target mean wait and is calculated as follows: target_wait / factor +If we want to have a chance between 1.8\%-0.2\% of making a waiting time target, then the average patient should +have a waiting time between a quarter and a sixth of the target. Therefore: +The mean wait should sit somewhere between target_wait/factor=6 < Average Waiting Time < target_wait/factor=4 +} +\examples{ +# If the target wait is 52 weeks then the target mean wait with a factor of 4 would be 13 +# weeks and with a factor of 6 it would be 8.67 weeks. +average_wait(52, 4) + +} diff --git a/man/example_function.Rd b/man/example_function.Rd deleted file mode 100644 index 31ebb02..0000000 --- a/man/example_function.Rd +++ /dev/null @@ -1,27 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/example_function.R -\name{example_function} -\alias{example_function} -\title{Example function for getting started} -\usage{ -example_function(input1, input2) -} -\arguments{ -\item{input1}{Something you want to put into the function, this could be a number, character etc.} - -\item{input2}{Something you want to put into the function, this could be a number, character etc.} -} -\value{ -a character string of both inputs -} -\description{ -This is an example function to help people getting involved. The function below takes two inputs, converts -them to characters and then concatenates them as a string for output. I've explicitly used the 'return' function at the end -, which is good practice, but the function will return the last row if not. Once you've written your function, if working in RStudio -, go to the 'Code' menu and select 'Insert Roxygen Skeleton', which will insert the metadata tags like this. Fill them in, and they -will be used to build the help files etc. -} -\examples{ -example_function("something", 1234) - -} diff --git a/man/queue_load.Rd b/man/queue_load.Rd new file mode 100644 index 0000000..ef8bab2 --- /dev/null +++ b/man/queue_load.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/queue_load.R +\name{queue_load} +\alias{queue_load} +\title{Queue Load} +\usage{ +queue_load(demand, capacity) +} +\arguments{ +\item{demand}{Numeric value of rate of demand in same units as target wait - e.g. if target wait is weeks, then demand in units of patients/week.} + +\item{capacity}{Numeric value of the number of patients that can be served (removals) from the waiting list each week.} +} +\value{ +Numeric value of load which is the ratio between demand and capacity +} +\description{ +Calculates the queue load. The queue load is the number of arrivals that occur for every patient leaving the queue (given that the +waiting list did not empty). +It could also be described as the rate of service at the queue. +The queue load is calculated by dividing the demand by the capacity: +queue_load = demand / capacity +} +\examples{ +# If 30 patients are added to the waiting list each week (demand) and 27 removed (capacity) +# this results in a queue load of 1.11 (30/27) +queue_load(30,27) + + +} diff --git a/man/relief_capacity.Rd b/man/relief_capacity.Rd new file mode 100644 index 0000000..25f730e --- /dev/null +++ b/man/relief_capacity.Rd @@ -0,0 +1,35 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/relief_capacity.R +\name{relief_capacity} +\alias{relief_capacity} +\title{Relief Capacity} +\usage{ +relief_capacity(demand, queue_size, target_queue_size, weeks_to_target) +} +\arguments{ +\item{demand}{Numeric value of rate of demand in same units as target wait - e.g. if target wait is weeks, then demand in units of patients/week.} + +\item{queue_size}{Numeric value of current number of patients in queue.} + +\item{target_queue_size}{Numeric value of desired number of patients in queue.} + +\item{weeks_to_target}{Numeric value of desired number of time-steps to reach the target queue size by.} +} +\value{ +A numeric value of the required rate of capacity to achieve a target queue size in a given period of time. +} +\description{ +Calculates required relief capacity to achieve target queue size in a given period of time as a function of demand, queue size, target queue size and time period. + +Relief Capacity is required if Queue Size > 2 * Target Queue Size. + +Relief Capacity = Current Demand + (Queue Size - Target Queue Size)/Time Steps +} +\examples{ +# If demand is 30 patients per week, the current queue size is 1200 and the target is to achieve a queue size of 390 in 26 weeks, then + +# Relief Capacity = 30 + (1200 - 390)/26 = 61.15 patients per week. + +relief_capacity(30, 1200, 390, 26) + +} diff --git a/man/target_capacity.Rd b/man/target_capacity.Rd new file mode 100644 index 0000000..84d8cc3 --- /dev/null +++ b/man/target_capacity.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/target_capacity.R +\name{target_capacity} +\alias{target_capacity} +\title{Target Capacity} +\usage{ +target_capacity(demand, target_wait, F = 1) +} +\arguments{ +\item{demand}{Numeric value of rate of demand in same units as target wait - e.g. if target wait is weeks, then demand in units of patients/week.} + +\item{target_wait}{Numeric value of number of weeks that has been set as the target within which the patient should be seen.} +} +\value{ +A numeric value of target capacity required to achieve a target waiting time. +} +\description{ +Calculates the target capacity to achieve a given target waiting time as a function of observed demand, target waiting time and a variability of demand parameter F. + +F defaults to 1. + +Target Capacity = Demand + 2 * ( 1 + 4 * F ) / Target Wait +} +\examples{ + +# If the target wait is 52 weeks, demand is 30 patients per week and F = 3 then +# Target capacity = 30 + 2*(1+4*3)/52 = 30.5 patients per week. + +target_capacity(30,52,3) + +} diff --git a/man/target_queue_size.Rd b/man/target_queue_size.Rd new file mode 100644 index 0000000..288bd53 --- /dev/null +++ b/man/target_queue_size.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/target_queue_size.R +\name{target_queue_size} +\alias{target_queue_size} +\title{Target Queue Size} +\usage{ +target_queue_size(demand, target_wait, factor = 4) +} +\arguments{ +\item{demand}{Numeric value of rate of demand in same units as target wait - e.g. if target wait is weeks, then demand in units of patients/week.} + +\item{target_wait}{Numeric value of number of weeks that has been set as the target within which the patient should be seen.} + +\item{factor}{Numeric factor used in average wait calculation - to get a quarter of the target use factor=4 and one sixth of the target use factor = 6 etc. Defaults to 4.} +} +\value{ +Numeric target queue length. +} +\description{ +Uses Little's Law to calculate the target queue size to achieve a target waiting time as a function of observed demand, target wait and a variability factor used in the target mean waiting time calculation. + +Target Queue Size = Demand * Target Wait / 4. + +The average wait should sit somewhere between +target_wait/factor=6 < Average Waiting Time < target_wait/factor=4 +The factor defaults to 4. + +Only applicable when Capacity > Demand. +} +\examples{ +# If demand is 30 patients per week and the target wait is 52 weeks, then the +# Target queue size = 30 * 52/4 = 390 patients. + +target_queue_size(30,52,4) + +} diff --git a/man/waiting_list_pressure.Rd b/man/waiting_list_pressure.Rd new file mode 100644 index 0000000..2491533 --- /dev/null +++ b/man/waiting_list_pressure.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/waiting_list_pressure.R +\name{waiting_list_pressure} +\alias{waiting_list_pressure} +\title{Calculate the waiting list pressure} +\usage{ +waiting_list_pressure(mean_wait, target_wait) +} +\arguments{ +\item{mean_wait}{Numeric value of target mean waiting time to achieve a given target wait} + +\item{target_wait}{Numeric value of the number of weeks that has been set as the target within which the patient should be seen} +} +\value{ +Numeric value of wait_pressure which is the waiting list pressure +} +\description{ +For a waiting list with target waiting time, the pressure on the waiting list is twice +the mean delay divided by the waiting list target. +The pressure of any given waiting list should be less than 1. +If the pressure is greater than 1 then the waiting list is most likely going to miss its target. +The waiting list pressure is calculated as follows: +pressure = 2 x mean_wait / target_wait +} +\examples{ +waiting_list_pressure(63,52) + +} diff --git a/vignettes/example_walkthrough.Rmd b/vignettes/example_walkthrough.Rmd index d4740df..768a5e4 100644 --- a/vignettes/example_walkthrough.Rmd +++ b/vignettes/example_walkthrough.Rmd @@ -23,7 +23,7 @@ This vignette is a practical demonstration of the {NHSRwaitinglist} functions, u The example is centred on a P4 (priority 4) Ear, Nose & Throat (ENT) waiting list at an acute hospital. The package functions we will be using are: -```{r child = 'functions_table.Rmd'} +```{r child = 'functions_table.md'} ``` ## Setup @@ -219,7 +219,7 @@ Closer attention should be paid to P2 procedures. This worked example aims to demonstrate the functions available in this package. In chronological order of application they were: -```{r child = 'functions_table.Rmd'} +```{r child = 'functions_table.md'} ``` ## Further reading diff --git a/vignettes/functions_table.Rmd b/vignettes/functions_table.md similarity index 100% rename from vignettes/functions_table.Rmd rename to vignettes/functions_table.md