Open DanChaltiel opened 1 year ago
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)
Current use:
Problem: when the database is corrected,
wrong
is not of the right length (eventually 0).Proposition:
With
predicate
to be evaluated withindata
.