Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update phe_dsr so that it will work inside a function #60

Open
Olivia-Box-Power opened this issue Sep 30, 2021 · 0 comments
Open

Update phe_dsr so that it will work inside a function #60

Olivia-Box-Power opened this issue Sep 30, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@Olivia-Box-Power
Copy link
Collaborator

Would it be possible to update phe_dsr so that it can be used within a function, with field names passed using {{ }}?

library("PHEindicatormethods")
library("tidyverse")




df <- data.frame(indicatorid = rep(c(1234, 5678, 91011, 121314), each = 19 * 2 * 5),
                 year = rep(2006:2010, each = 19 * 2),
                 sex = rep(rep(c("Male", "Female"), each = 19), 5),
                 ageband = rep(c(0,5,10,15,20,25,30,35,40,45,
                                 50,55,60,65,70,75,80,85,90), times = 10),
                 obs = sample(200, 19 * 2 * 5 * 4, replace = TRUE),
                 pop = sample(10000:20000, 19 * 2 * 5 * 4, replace = TRUE),
                 esp = rep(esp2013, times = 10))



phe_dsr_2 <- function(data,
                      count,
                      denominator,
                      ref_pop) {

data %>%
  group_by(indicatorid, year, sex) %>%
  phe_dsr(x = {{ count }},
          n = {{ denominator }},
          stdpop =  {{ ref_pop }},
          stdpoptype = "field")

}

phe_dsr_2(df, count =  obs, denominator = pop, ref_pop = esp)
#> Warning in if (deparse(substitute(stdpop)) %in% colnames(data)) {: the condition
#> has length > 1 and only the first element will be used
#> Error in phe_dsr(., x = {: stdpop is not a field name from data

Created on 2021-09-30 by the reprex package (v2.0.1)

@GeorgieAnderson GeorgieAnderson added the enhancement New feature or request label Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants