You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For me the main advantage of a for loop over map() in an interactive context is that I can easily continue the for loop after an interruption. An example workflow I regularly have:
slow_function<-function(x) {
if (x==5) {
stop("something went wrong")
}
x
}
to_process<-1:10results<-list()
for (iinto_process) {
results[[i]] <- slow_function(i)
}
#> Error in slow_function(i): something went wrong
print(i)
#> [1] 5# now fix `slow_function()`slow_function<-function(x) {
x
}
for (jinto_process[-(1:(i-1))]) {
results[[j]] <- slow_function(j)
}
print(results)
#> [[1]]#> [1] 1#> #> [[2]]#> [1] 2#> #> [[3]]#> [1] 3#> #> [[4]]#> [1] 4#> #> [[5]]#> [1] 5#> #> [[6]]#> [1] 6#> #> [[7]]#> [1] 7#> #> [[8]]#> [1] 8#> #> [[9]]#> [1] 9#> #> [[10]]#> [1] 10
For me the main advantage of a for loop over
map()
in an interactive context is that I can easily continue the for loop after an interruption. An example workflow I regularly have:Created on 2023-09-05 with reprex v2.0.2
The text was updated successfully, but these errors were encountered: