Skip to content

Commit cb44174

Browse files
committed
resolved tidy/pipe compliance issue by moving the error check to after the columns have been mapped.
1 parent be4ed24 commit cb44174

5 files changed

Lines changed: 28 additions & 42 deletions

File tree

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ NHSEI_AHSN_limits.R
1616
^dev$
1717
^codecov\.yml$
1818
^\.github$
19+
test_func.R

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export(outliers)
1616
export(phi)
1717
export(source_data)
1818
export(tau2)
19-
export(tst_func)
2019
import(ggplot2)
2120
importFrom(dplyr,"%>%")
2221
importFrom(dplyr,arrange)

R/funnel_plot.R

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,30 +179,23 @@ funnel_plot <- function(.data, numerator, denominator, group
179179

180180

181181
# build initial dataframe of obs/predicted, with error message caught here in 'try'
182-
182+
# Main error check here, some moved after tidyeval mapping as they conflict.
183183
if (missing(denominator)) {
184-
stop("Need to specify model denominator")
184+
stop("Need to specify denominator column")
185185
}
186186
if (missing(numerator)) {
187-
stop("Need to supply numerator")
187+
stop("Need to supply numerator column")
188188
}
189189
if (missing(title)) {
190190
title <- ("Untitled Funnel Plot")
191191
}
192-
if (missing(numerator)) {
193-
stop("Need to supply the column name for numerator")
194-
}
192+
195193

196-
if (class(denominator)[1] == "array") {
197-
denominator <- as.numeric(denominator)
198-
}
199194

200-
if(identical(numerator,denominator)){
201-
stop("Numerator and denominator are the same. Please check your inputs")
202-
}
203-
204-
if(length(plot_cols) < 4){
205-
stop("Please supply a vector of 4 colours for funnel limits, in order: 95% Poisson, 99.8% Poisson, 95% OD-adjusted, 99.8% OD-adjusted, even if you are only using one set of limits.")
195+
if(length(plot_cols) < 8){
196+
stop("Please supply a vector of 4 colours for funnel limits, in order: 95% Lower Poisson, 95% Upper Poisson
197+
, 99.8% Lower Poisson, 99.8% Upper Poisson, 95% Upper OD-adjusted, 95% Lower OD-adjusted,
198+
99.8% Lower OD-adjusted, 99.8% Upper OD-adjusted, even if you are only using one set of limits.")
206199
}
207200

208201
if(!(label %in% c("outlier", "outlier_lower", "outlier_upper", "highlight"
@@ -271,7 +264,13 @@ funnel_plot <- function(.data, numerator, denominator, group
271264
numerator <- quo_name(enquo(numerator))
272265
denominator <- quo_name(enquo(denominator))
273266
group <- quo_name(enquo(group))
274-
267+
268+
# error check
269+
if(identical(.data[[numerator]],.data[[denominator]])){
270+
stop("Numerator and denominator are the same. Please check your inputs")
271+
}
272+
273+
# now make working table
275274
mod_plot <- data.frame(numerator=as.numeric(.data[[numerator]])
276275
,denominator=as.numeric(.data[[denominator]])
277276
, group=as.factor(.data[[group]]))

R/test_func.R

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,18 @@ tst_func <- function(.data, numerator, denominator, group){
2929
}
3030

3131

32-
# medpar
33-
#
32+
library(COUNT)
33+
data(medpar)
34+
35+
medpar$provnum<-factor(medpar$provnum)
36+
medpar$los<-as.numeric(medpar$los)
37+
38+
mod<- glm(los ~ hmo + died + age80 + factor(type), family="poisson", data=medpar)
39+
summary(mod)
40+
41+
# Get predicted value for ratio
42+
medpar$prds<- predict(mod, type="response")
43+
3444
tst_func(medpar, los, prds, provnum)
3545

3646
funnel_plot(medpar, los, prds, provnum)

man/tst_func.Rd

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)