Skip to content

Commit

Permalink
resolved missing brace in function help due to line break and param n…
Browse files Browse the repository at this point in the history
…ames that were out of sync in build_limits_lookup.
  • Loading branch information
chrismainey committed Apr 11, 2024
1 parent df6d1af commit 66c5d7a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
15 changes: 7 additions & 8 deletions R/build_limits_lookup.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#' Function to build funnel limits
#' @description Internal function for funnel plot to build the control limits prior to plotting.
#' @param min_preds Minimum predicted value for range of x-axis
#' @param max_preds Maximum predicted value for range of x-axis
#' @param min_ratio Minimum ratio value for range of y-axis
#' @param max_ratio Maximum ratio value for range of y-axis
#' @param draw_unadjusted TRUE/FALSE Draw Poisson distribution limits?
#' @param min_x Minimum predicted value for range of x-axis
#' @param max_x Maximum predicted value for range of x-axis
#' @param min_y Minimum ratio value for range of y-axis
#' @param max_y Maximum ratio value for range of y-axis
#' @param draw_adjusted TRUE/FALSE Use overdispersion adjustment
#' @param tau2 If using draw_adjusted, what is the tau2 ("between" standard error) to use?
#' @param data_type SR, PR or RC. Used to set target reference
Expand All @@ -18,12 +17,12 @@
build_limits_lookup<-function(min_x, max_x, min_y, max_y
, draw_adjusted, tau2, data_type, sr_method
, target, multiplier, denominators){


# general limits + tau2 limits table
set.seed(1)


if(data_type=="SR"){
number.seq <- seq(1.1, as.numeric(max_x), length.out = 1000)
} else {
Expand Down
37 changes: 18 additions & 19 deletions R/funnel_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
#' \item{\code{"both"}}{ - Labels both the highlighted values(s), upper and lower outliers, determined in relation to the `limit` argument.}
#' \item{\code{"both_lower"}}{ - Labels both the highlighted values(s) and lower outliers, determined in relation to the `limit` argument.}
#' \item{\code{"both_upper"}}{ - Labels both the highlighted values(s) and upper outliers, determined in relation to the `limit` argument.}
#' \item{\code{NA}}{ - No labels applied}
#' }
#' \item{\code{NA}}{ - No labels applied}}
#' @param highlight Single or vector of points to highlight, with a different colour and point style. Should correspond to values specified to `group`. Default is NA, for no highlighting.
#' @param label_outliers Deprecated. Please use the `label` argument instead.
#' @param Poisson_limits Deprecated. Please use the `draw_unadjusted` argument instead.
Expand Down Expand Up @@ -191,12 +190,12 @@ funnel_plot <- function(.data, numerator, denominator, group
if (missing(title)) {
title <- ("Untitled Funnel Plot")
}



if(length(plot_cols) < 8){
stop("Please supply a vector of 4 colours for funnel limits, in order: 95% Lower Poisson, 95% Upper Poisson
, 99.8% Lower Poisson, 99.8% Upper Poisson, 95% Upper OD-adjusted, 95% Lower OD-adjusted,
, 99.8% Lower Poisson, 99.8% Upper Poisson, 95% Upper OD-adjusted, 95% Lower OD-adjusted,
99.8% Lower OD-adjusted, 99.8% Upper OD-adjusted, even if you are only using one set of limits.")
}

Expand Down Expand Up @@ -224,7 +223,7 @@ funnel_plot <- function(.data, numerator, denominator, group
}



# Define vector for scale colours
plot_cols<-c(

Expand All @@ -237,41 +236,41 @@ funnel_plot <- function(.data, numerator, denominator, group
"99.8% Lower Overdispersed" = plot_cols[7],
"99.8% Upper Overdispersed" = plot_cols[8]
)

# map columns for tidyeval compliance

numerator <- quo_name(enquo(numerator))
denominator <- quo_name(enquo(denominator))
group <- quo_name(enquo(group))

# error check
if(identical(.data[[numerator]],.data[[denominator]])){
stop("Numerator and denominator are the same. Please check your inputs")
}

# Error handling for highlight argument
if(!is.na(highlight[1])){

if(!is.character(highlight[1])) {
stop("Please supply `highlight` in character format, or a character vector")
}

# check for missing highlight levels
labs_present <- apply(sapply(X = highlight, FUN = grepl, x=.data[[group]]), 2, any)
labs_missing <- names(labs_present[labs_present == FALSE])

if (length(labs_missing)>0){

stop(paste0("Value(s):'"
, paste(labs_missing,collapse=", ")
, "' specified to `highlight` not found in `group` variable.
Are you trying to highlight a group that is missing from your
, "' specified to `highlight` not found in `group` variable.
Are you trying to highlight a group that is missing from your
data, or is it a typo?"
))

}
}

# now make working table
mod_plot <- data.frame(numerator=as.numeric(.data[[numerator]])
,denominator=as.numeric(.data[[denominator]])
Expand Down Expand Up @@ -343,8 +342,8 @@ funnel_plot <- function(.data, numerator, denominator, group
message("No overdispersion detected, or draw_adjusted set to FALSE, plotting using unadjusted limits")
draw_unadjusted <- TRUE
}



# Calculate both adjusted and unadjusted control limits. This calculates limits for
# for both a range of denominators for plotting as well as the denominators present
Expand Down

0 comments on commit 66c5d7a

Please sign in to comment.