Skip to content

Commit

Permalink
Corrected errors in layout of code
Browse files Browse the repository at this point in the history
  • Loading branch information
jacgrout committed May 3, 2024
1 parent fc99f61 commit 7d88592
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion R/create_bulk_synthetic_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#'
#' @examples create_bulk_synthetic_data(demo_df)

create_bulk_synthetic_data <- function(bulk_data){
create_bulk_synthetic_data <- function(bulk_data) {
result <- bulk_data |>

Check warning on line 20 in R/create_bulk_synthetic_data.R

View workflow job for this annotation

GitHub Actions / lint

file=R/create_bulk_synthetic_data.R,line=20,col=0,[indentation_linter] Indentation should be 2 spaces but is 0 spaces.
purrr::pmap(create_waiting_list) |>
dplyr::bind_rows()
Expand Down
20 changes: 11 additions & 9 deletions R/create_waiting_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#' @param n 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 mean_arrival_rate Numeric value of mean daily arrival rate.
#' @param mean_wait Numeric value of mean wait time for treatment/on waiting list.
#' @param mean_wait Numeric value of mean wait time for treatment/on waiting
#' list.
#' @param start_date Character value of date from which to start generated
#' waiting list.
#' @param limit_removals Defaults to TRUE
Expand All @@ -25,20 +26,21 @@

create_waiting_list <- function(n, mean_arrival_rate, mean_wait,
start_date = Sys.Date(), limit_removals = TRUE,
sd = 0, rott = 0, ...){
sd = 0, rott = 0, ...) {

dots <- list(...)

#Generate date range and number of referrals for each date (with or without
#random variation around mean_arrival_rate)
dates <- seq.Date(from = as.Date(start_date,format="%Y-%m-%d"),length.out = n,
dates <- seq.Date(from = as.Date(start_date,format="%Y-%m-%d"),

Check warning on line 35 in R/create_waiting_list.R

View workflow job for this annotation

GitHub Actions / lint

file=R/create_waiting_list.R,line=35,col=47,[commas_linter] Commas should always have a space after.

Check warning on line 35 in R/create_waiting_list.R

View workflow job for this annotation

GitHub Actions / lint

file=R/create_waiting_list.R,line=35,col=53,[infix_spaces_linter] Put spaces around all infix operators.
length.out = n,
by = "day")
counts <- pmax(0,rnorm(n, mean = mean_arrival_rate, sd = sd))

Check warning on line 38 in R/create_waiting_list.R

View workflow job for this annotation

GitHub Actions / lint

file=R/create_waiting_list.R,line=38,col=20,[commas_linter] Commas should always have a space after.
referrals <- rep(dates, times = counts)

#set random waiting time in days for each referral received with exponential
#distribution rate 1/mean_waiting_time
values <- rexp(length(referrals),1/mean_wait)
values <- rexp(length(referrals), 1/mean_wait)

Check warning on line 43 in R/create_waiting_list.R

View workflow job for this annotation

GitHub Actions / lint

file=R/create_waiting_list.R,line=43,col=38,[infix_spaces_linter] Put spaces around all infix operators.

#Create dataframe of referrals and calculate removal date
test_df <- data.frame(addition_date = referrals, wait_length = values)
Expand All @@ -48,20 +50,20 @@ create_waiting_list <- function(n, mean_arrival_rate, mean_wait,
#simulate non-zero waitlist at end of simulated period.
if (limit_removals) {
test_df$removal_date[test_df$removal_date >
(as.Date(start_date,format="%Y-%m-%d") + n)] <- NA
(as.Date(start_date, format="%Y-%m-%d") + n)] <- NA
test_df$wait_length[is.na(test_df$removal_date)] <- NA
}

#Randomly flag user defined proportion of referrals as ROTT
test_df$rott <- FALSE
sample_list <- sample(1:nrow(test_df),nrow(test_df)*rott, replace = FALSE)
sample_list <- sample(1:nrow(test_df), nrow(test_df)*rott, replace = FALSE)
test_df$rott[sample_list] <- TRUE

#Add a patient ID to each referral and prepare data for return
test_df$pat_id <- 1:nrow(test_df)
test_df <- test_df[order(test_df$addition_date),c("pat_id","addition_date",
"removal_date","wait_length",
"rott")]
test_df <- test_df[order(test_df$addition_date),
c("pat_id", "addition_date",
"removal_date", "wait_length", "rott")]

return( dplyr::as_tibble(c(dots, test_df)) )
}
Expand Down
20 changes: 11 additions & 9 deletions data-raw/demo-data.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
## code to prepare `demo-data` dataset goes here
demo_df <- data.frame(hospital_site=c("ABC001","DHR70","JRW20","RFW002","DHR70"),
main_spec_code = c(100,110,120,130,100),
opcs4_code = c("T202","W401","F344","C866","T272"),
n= 366,
mean_arrival_rate= c(50,25,20,40,50),
mean_wait = c(21,20,10,30,21),
start_date = c("2024-01-01","2023-04-01","2024-04-01","2023-01-01","2024-01-01"),
sd=10,
rott=c(0,0.1,0.05,0.2,0.1)
demo_df <- data.frame(hospital_site = c("ABC001", "DHR70", "JRW20", "RFW002",
"DHR70"),
main_spec_code = c(100, 110, 120, 130, 100),

Check warning on line 4 in data-raw/demo-data.R

View workflow job for this annotation

GitHub Actions / lint

file=data-raw/demo-data.R,line=4,col=21,[indentation_linter] Indentation should be 2 spaces but is 21 spaces.
opcs4_code = c("T202", "W401", "F344", "C866", "T272"),
n = 366,
mean_arrival_rate = c(50, 25, 20, 40, 50),
mean_wait = c(21, 20, 10, 30, 21),
start_date = c("2024-01-01", "2023-04-01", "2024-04-01",
"2023-01-01", "2024-01-01"),
sd = 10,

Check warning on line 11 in data-raw/demo-data.R

View workflow job for this annotation

GitHub Actions / lint

file=data-raw/demo-data.R,line=11,col=21,[indentation_linter] Indentation should be 2 spaces but is 21 spaces.
rott = c(0, 0.1, 0.05, 0.2, 0.1)
)

Check warning on line 13 in data-raw/demo-data.R

View workflow job for this annotation

GitHub Actions / lint

file=data-raw/demo-data.R,line=13,col=2,[indentation_linter] Indentation should be 0 spaces but is 2 spaces.

usethis::use_data(demo_df, overwrite = TRUE)

0 comments on commit 7d88592

Please sign in to comment.