# NOT RUN {
isolate_example("Contain side effects", {
# Normally, `drake` reacts to changes in dependencies.
x <- 4
make(plan = drake_plan(y = sqrt(x)))
x <- 5
make(plan = drake_plan(y = sqrt(x)))
make(plan = drake_plan(y = sqrt(4) + x))
# But not with ignore().
make(plan = drake_plan(y = sqrt(4) + ignore(x))) # Builds y.
x <- 6
make(plan = drake_plan(y = sqrt(4) + ignore(x))) # Skips y.
make(plan = drake_plan(y = sqrt(4) + ignore(x + 1))) # Skips y.
# ignore() works with functions and multiline code chunks.
f <- function(x) {
ignore({
x <- x + 1
x <- x + 2
})
x # Not ignored.
}
make(plan = drake_plan(y = f(2)))
readd(x)
# Changes the content of the ignore() block:
f <- function(x) {
ignore({
x <- x + 1
})
x # Not ignored.
}
make(plan = drake_plan(x = f(2)))
readd(x)
})
# }
Run the code above in your browser using DataLab