Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linting to continuous integration #47

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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]

name: lint

jobs:
lint:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::lintr, local::.
needs: lint

- name: Lint
run: lintr::lint_package()
shell: Rscript {0}
env:
LINTR_ERROR_ON_LINT: true
5 changes: 5 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
linters: linters_with_defaults(
object_usage_linter(NULL))
exclude: "# nolint"
exclude_start: "# Begin Exclude Linting"
exclude_end: "# End Exclude Linting"
52 changes: 29 additions & 23 deletions R/average_wait.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
#' @title Average Waiting Time
#'
#' @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
#'
#' @param target_wait Numeric value of the number of weeks that has been set as the target within which the patient should be seen.
#' @param 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.
#'
#' @return Numeric value of target mean waiting time to achieve a given target wait.
#' @export
#'
#' @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)
#'
average_wait <- function(target_wait, factor = 4) {
target_mean_wait <- target_wait / factor
return(target_mean_wait)
}
#' @title Average Waiting Time
#'
#' @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.
#'
#' @param target_wait Numeric value of the number of weeks that has been set as
#' the target within which the patient should be seen.
#' @param 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.
#'
#' @return Numeric value of target mean waiting time to achieve a given target
#' wait.
#'
#' @export
#'
#' @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)
average_wait <- function(target_wait, factor = 4) {
target_mean_wait <- target_wait / factor
return(target_mean_wait)
}
50 changes: 25 additions & 25 deletions R/queue_load.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#' @title Queue Load
#'
#' @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
#'
#' @param 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.
#' @param capacity Numeric value of the number of patients that can be served (removals) from the waiting list each week.
#'
#' @return Numeric value of load which is the ratio between demand and capacity
#' @export
#'
#' @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)
#'
#'
queue_load <- function(demand, capacity) {
load <- demand / capacity
return (load)
}
#' @title Calculate Queue Load
#'
#' @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.
#'
#' @param 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.
#' @param capacity Numeric value of the number of patients that can be served
#' (removals) from the waiting list each week.
#'
#' @return Numeric value of load which is the ratio between demand and capacity.
#'
#' @export
#'
#' @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)
queue_load <- function(demand, capacity) {
load <- demand / capacity
return(load)
}
64 changes: 35 additions & 29 deletions R/relief_capacity.R
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
#' @title Relief Capacity
#'
#' @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
#'
#' @param 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.
#' @param queue_size Numeric value of current number of patients in queue.
#' @param target_queue_size Numeric value of desired number of patients in queue.
#' @param weeks_to_target Numeric value of desired number of time-steps to reach the target queue size by.
#'
#' @return A numeric value of the required rate of capacity to achieve a target queue size in a given period of time.
#' @export
#'
#' @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)
#'
relief_capacity <- function(demand, queue_size, target_queue_size, weeks_to_target) {
rel_cap <- demand + (queue_size - target_queue_size) / weeks_to_target
return(rel_cap)
}
#' @title Calculate Relief Capacity
#'
#' @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.
#'
#' @param 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.
#' @param queue_size Numeric value of current number of patients in queue.
#' @param target_queue_size Numeric value of desired number of patients in
#' queue.
#' @param weeks_to_target Numeric value of desired number of time-steps to reach
#' the target queue size by.
#'
#' @return A numeric value of the required rate of capacity to achieve a target
#' queue size in a given period of time.
#'
#' @export
#'
#' @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)
relief_capacity <- function(
demand, queue_size, target_queue_size, weeks_to_target) {
rel_cap <- demand + (queue_size - target_queue_size) / weeks_to_target
return(rel_cap)
}
56 changes: 30 additions & 26 deletions R/target_capacity.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
#' @title Target Capacity
#'
#' @description
#' Calculates the target capacity to achieve a given target waiting time as a function of observed demand, target waiting time and a variability coefficient F.
#'
#' Target Capacity = Demand + 2 * ( 1 + 4 * F ) / Target Wait
#' F defaults to 1.
#'
#' @param 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.
#' @param target_wait Numeric value of number of weeks that has been set as the target within which the patient should be seen.
#' @param F Variability coefficient, F = V/C * (D/C)^2 where C is the current number of operations per week; V is the current variance in the number of operations per week; D is the observed demand. Defaults to 1.
#'
#' @return A numeric value of target capacity required to achieve a target waiting time.
#' @export
#'
#' @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)
#'
target_capacity <- function(demand, target_wait, F = 1) {
target_cap <- demand + 2 * ( 1 + 4 * F ) / target_wait
return(target_cap)
}
#' @title Calculate Target Capacity
#'
#' @description Calculates the target capacity to achieve a given target waiting
#' time as a function of observed demand, target waiting time and a variability
#' coefficient F.
#'
#' Target Capacity = Demand + 2 * ( 1 + 4 * F ) / Target Wait F defaults to 1.
#'
#' @param 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.
#' @param target_wait Numeric value of number of weeks that has been set as the
#' target within which the patient should be seen.
#' @param F Variability coefficient, F = V/C * (D/C)^2 where C is the current
#' number of operations per week; V is the current variance in the number of
#' operations per week; D is the observed demand. Defaults to 1.
#'
#' @return A numeric value of target capacity required to achieve a target
#' waiting time.
#'
#' @export
#'
#' @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)
target_capacity <- function(demand, target_wait, F = 1) {

Check warning on line 27 in R/target_capacity.R

View workflow job for this annotation

GitHub Actions / lint

file=R/target_capacity.R,line=27,col=50,[object_name_linter] Variable and function name style should match snake_case or symbols.
target_cap <- demand + 2 * (1 + 4 * F) / target_wait

Check warning on line 28 in R/target_capacity.R

View workflow job for this annotation

GitHub Actions / lint

file=R/target_capacity.R,line=28,col=41,[T_and_F_symbol_linter] Use FALSE instead of the symbol F.
return(target_cap)
}
65 changes: 34 additions & 31 deletions R/target_queue_size.R
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
#' @title Target Queue Size
#'
#' @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.
#'
#' @param 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.
#' @param target_wait Numeric value of number of weeks that has been set as the target within which the patient should be seen.
#' @param 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.
#'
#' @return Numeric target queue length.
#' @export
#'
#' @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)
#'
target_queue_size <- function(demand, target_wait, factor = 4) {
mean_wait <- average_wait(target_wait, factor)
target_queue_length <- demand * mean_wait
return(target_queue_length)
}
#' @title Calculate Target Queue Size
#'
#' @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.
#'
#' @param 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.
#' @param target_wait Numeric value of number of weeks that has been set as the
#' target within which the patient should be seen.
#' @param 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.
#'
#' @return Numeric target queue length.
#'
#' @export
#'
#' @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)
target_queue_size <- function(demand, target_wait, factor = 4) {
mean_wait <- average_wait(target_wait, factor)
target_queue_length <- demand * mean_wait
return(target_queue_length)
}
46 changes: 24 additions & 22 deletions R/waiting_list_pressure.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
#' @title Calculate 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
#'
#' @param mean_wait Numeric value of target mean waiting time to achieve a given target wait
#' @param target_wait Numeric value of the number of weeks that has been set as the target within which the patient should be seen
#'
#' @return Numeric value of wait_pressure which is the waiting list pressure
#' @export
#'
#' @examples
#' waiting_list_pressure(63,52)
#'
waiting_list_pressure <- function(mean_wait, target_wait) {
wait_pressure <- 2 * mean_wait / target_wait
return(wait_pressure)
}
#' @title Calculate 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 * mean_wait / target_wait.
#'
#' @param mean_wait Numeric value of target mean waiting time to achieve a given
#' target wait.
#' @param target_wait Numeric value of the number of weeks that has been set as
#' the target within which the patient should be seen.
#'
#' @return Numeric value of wait_pressure which is the waiting list pressure.
#'
#' @export
#'
#' @examples
#' waiting_list_pressure(63, 52)
waiting_list_pressure <- function(mean_wait, target_wait) {
wait_pressure <- 2 * mean_wait / target_wait
return(wait_pressure)
}
Loading
Loading