-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from nhs-r-community/8-lint-action
Add linting to continuous integration
- Loading branch information
Showing
15 changed files
with
767 additions
and
713 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
target_cap <- demand + 2 * (1 + 4 * F) / target_wait | ||
return(target_cap) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.