Skip to content

Commit be4ed24

Browse files
committed
Added simple tester function for tidyeval as well as main function. Tester works, main doesnt
1 parent 2ca235b commit be4ed24

7 files changed

Lines changed: 104 additions & 13 deletions

File tree

DESCRIPTION

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ License: MIT + file LICENSE
1818
URL: https://nhs-r-community.github.io/FunnelPlotR/, https://github.com/nhs-r-community/FunnelPlotR
1919
BugReports: https://github.com/nhs-r-community/FunnelPlotR/issues
2020
Encoding: UTF-8
21-
Imports: dplyr,
22-
ggrepel,
23-
ggplot2,
24-
scales
21+
Imports:
22+
dplyr,
23+
ggrepel,
24+
ggplot2,
25+
scales,
26+
rlang
2527
RoxygenNote: 7.2.3
2628
Suggests:
2729
testthat (>= 3.0.0),

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export(outliers)
1616
export(phi)
1717
export(source_data)
1818
export(tau2)
19+
export(tst_func)
1920
import(ggplot2)
2021
importFrom(dplyr,"%>%")
2122
importFrom(dplyr,arrange)
@@ -32,6 +33,7 @@ importFrom(ggplot2,theme_grey)
3233
importFrom(ggplot2,theme_minimal)
3334
importFrom(ggrepel,geom_label_repel)
3435
importFrom(ggrepel,geom_text_repel)
36+
importFrom(rlang,.data)
3537
importFrom(scales,comma)
3638
importFrom(stats,aggregate)
3739
importFrom(stats,na.omit)

R/funnel_plot.R

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#' overdispersed, funnel control limits. Limits may be inflated for overdispersion based on the methods of DerSimonian & Laird (1986), buy calculating a between unit standard deviation (\eqn{\tau})
55
#' and constructing an additive random effects models, originally used for meta-analyses of clinical trials data.
66
#' @encoding UTF-8
7+
#' @param .data A data frame containing a numerator, denominator and grouping field.
78
#' @param numerator A vector of the numerator (observed events/counts) values. Used as numerator of the Y-axis
89
#' @param denominator A vector of denominator (predicted/population etc.) Used as denominator of the Y-axis and the scale of the x-axis
910
#' @param group A vector of group names as character or factor. Used to aggregate and group points on plots
@@ -106,12 +107,13 @@
106107
#'
107108
#'
108109
#' @importFrom scales comma
110+
#' @importFrom rlang .data
109111
#' @importFrom ggrepel geom_text_repel
110112
#' @importFrom dplyr select filter arrange mutate summarise group_by %>% n
111113
#' @importFrom stats na.omit
112114
#' @import ggplot2
113115

114-
funnel_plot <- function(numerator, denominator, group
116+
funnel_plot <- function(.data, numerator, denominator, group
115117
, data_type = "SR", limit = 99, label = "outlier"
116118
, highlight = NA, draw_unadjusted = FALSE
117119
, draw_adjusted = TRUE, sr_method = "SHMI"
@@ -124,7 +126,8 @@ funnel_plot <- function(numerator, denominator, group
124126
, theme = funnel_clean()
125127
, label_outliers, Poisson_limits, OD_adjust
126128
, xrange, yrange
127-
, SHMI_rounding = TRUE){
129+
, SHMI_rounding = TRUE
130+
, ...){
128131

129132
# Version 0.4 deprecation warnings
130133
if (!missing(label_outliers)) {
@@ -262,11 +265,16 @@ funnel_plot <- function(numerator, denominator, group
262265
"99.8% Lower Overdispersed" = plot_cols[7],
263266
"99.8% Upper Overdispersed" = plot_cols[8]
264267
)
265-
266-
267-
mod_plot <- data.frame(numerator=as.numeric(numerator)
268-
,denominator=as.numeric(denominator)
269-
, group=as.factor(group))
268+
269+
# map columns for tidyeval compliance
270+
271+
numerator <- quo_name(enquo(numerator))
272+
denominator <- quo_name(enquo(denominator))
273+
group <- quo_name(enquo(group))
274+
275+
mod_plot <- data.frame(numerator=as.numeric(.data[[numerator]])
276+
,denominator=as.numeric(.data[[denominator]])
277+
, group=as.factor(.data[[group]]))
270278

271279

272280
mod_plot_agg<-aggregate_func(mod_plot)

R/test_func.R

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
3+
#' Test function
4+
#'
5+
#' @param .data data frame
6+
#' @param numerator tghe numearto
7+
#' @param denominator denom
8+
#' @param group the group
9+
#'
10+
#' @return a data frame stuck together
11+
#' @export
12+
#'
13+
#' @importFrom rlang .data
14+
#'
15+
tst_func <- function(.data, numerator, denominator, group){
16+
17+
numerator <- quo_name(enquo(numerator))
18+
denominator <- quo_name(enquo(denominator))
19+
group <- quo_name(enquo(group))
20+
21+
22+
23+
mod_plot <- data.frame(numerator=as.numeric(.data[[numerator]])
24+
,denominator=as.numeric(.data[[denominator]])
25+
, group=as.factor(.data[[group]]))
26+
27+
return(mod_plot)
28+
29+
}
30+
31+
32+
# medpar
33+
#
34+
tst_func(medpar, los, prds, provnum)
35+
36+
funnel_plot(medpar, los, prds, provnum)

dev/tests.R

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fp2<-funnel_plot(denominator=medpar$prds,numerator=medpar$los, multiplier = 100,
4040

4141
, sr_method = "SHMI",
4242
draw_unadjusted = FALSE, draw_adjusted=TRUE, highlight = c("0300121", "030073"), theme=funnel_grey(),
43-
plot_cols = c("#FF7F0EFF", "#000000", "#1F77B4FF","#1F77B4FF", "#9467BDFF", "#9467BDFF", "#2CA02CFF", "#2CA02CFF"))
43+
plot_cols = c("#000000", "#1F77B4FF", "#9467BDFF", "#2CA02CFF"))
4444

4545
#rm(fp2)
4646
fp2
@@ -67,6 +67,11 @@ fp<-funnel_plot(numerator=medpar$los, denominator=medpar$prds, group = medpar$pr
6767
title = 'Length of Stay Funnel plot for `medpar` data', draw_unadjusted = TRUE,
6868
draw_adjusted = TRUE, limit=99, label = "outlier", sr_method="SHMI")
6969

70+
71+
fp<-funnel_plot(medpar, los, prds, provnum,
72+
title = 'Length of Stay Funnel plot for `medpar` data', draw_unadjusted = TRUE,
73+
draw_adjusted = TRUE, limit=99, label = "outlier", sr_method="SHMI")
74+
7075
fp[[1]]
7176

7277
View(fp[[3]])
@@ -107,6 +112,17 @@ a<-funnel_plot(numerator=medpar$los, denominator=(medpar$prds*10), group = medpa
107112
title = 'Length of Stay Funnel plot for `medpar` data', draw_unadjusted = FALSE,
108113
draw_adjusted = TRUE, label_outliers = TRUE, sr_method="SHMI")
109114

115+
116+
a<-funnel_plot(numerator=medpar$los, denominator=(medpar$prds*10), group = medpar$provnum,
117+
data_type = "RC",#return_elements=c("plot"),
118+
title = 'Length of Stay Funnel plot for `medpar` data', draw_unadjusted = FALSE,
119+
draw_adjusted = TRUE, label_outliers = TRUE, sr_method="SHMI")
120+
121+
122+
123+
.data <- medpar
124+
numerator=los
125+
denominator=(medpar$prds*10), group = medpar$provnum,
110126
a[1]
111127

112128
a[[2]] %>%

man/funnel_plot.Rd

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tst_func.Rd

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)