Open IndrajeetPatil opened 3 months ago
It's a great recommendation, though maybe tough to come up with much robust enough to avoid false positives.
This would be possible if we could somehow determine whether a function is pure or not. A completely correct implementation is probably not feasible unless functions are annotated in some way.
Untested thoughts on how to cause headaches:
l <- as.list(1:5)
meany <- function() assign("l", c(41, 42), envir = parent.frame())
lapply(l, function(x) {
meany()
x / sd(unlist(l))
})
Arguably, this is not the best example, but it demonstrates the inefficiency of calling functionals that unnecessarily keep recomputing something in each iteration when it needs to be computed just once and reused.
Created on 2024-06-19 with reprex v2.1.0