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

manual_correction() is not really usable #7

Open
DanChaltiel opened this issue Sep 19, 2023 · 1 comment
Open

manual_correction() is not really usable #7

DanChaltiel opened this issue Sep 19, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@DanChaltiel
Copy link
Owner

Current use:

l = with(data, which(subjid==111 & dqlq=="2020/03"))
manual_correction(data, dqlq, rows=l, wrong="2020/03", correct="2021/03")

wrong = ymd("2011/11/29", "2021/01/12", "2019/12/11", "2020/12/28")
l=which(data$tc_dt %in% wrong & data$subjid  %in% c(128,196,17,73))
wrong = data$tc_dt[l]
manual_correction(data, tc_dt, rows=l, wrong=wrong, correct=rep(NA, 4))

Problem: when the database is corrected, wrong is not of the right length (eventually 0).

Proposition:

manual_correction(data, tc_dt, predicate=tc_dt %in% wrong & subjid  %in% c(128,196,17,73), correct=rep(NA, 4))

With predicate to be evaluated within data.

@DanChaltiel DanChaltiel added the bug Something isn't working label Sep 19, 2023
@DanChaltiel
Copy link
Owner Author

  • It seems risky to correct multiple cases at once.
  • It seems incorrect to invisibly change data, piping feels better
f = function(data, predicate, column, wrong, right, multiple=FALSE){
  x = data %>% filter(!!enquo(predicate) & {{column}}==wrong) %>% nrow()
  if(x==0) stop("already corrected")
  if(x>1 && !multiple) stop("More than 1 row corrected")
  
  data %>% 
    mutate(
      {{column}} := ifelse(!!enquo(predicate) & {{column}}==wrong, right, {{column}})
    )
}
df = iris %>% f(Species=="virginica" & Sepal.Width==3.6, column=Sepal.Length, wrong=7.2, right=999)
df = iris %>% f(Species=="virginica" & Sepal.Width==3.6, column=Sepal.Length, wrong=998, right=999)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant