-
Notifications
You must be signed in to change notification settings - Fork 38
Error when plotting a {sf} object #264
Copy link
Copy link
Closed
Description
Hi
Not sure if it comes from {furrr}, {sf} or another package in between, ({future}, {vctrs} ?). Let me know if I should report elsewhere...
When plotting each row of a spatial layer ({sf} polygon object) with {ggplot2} or base plot, it works with walk but I get some errors using future_walk.
This code used to work with previous versions of the packages, but I can't give precisely the version number of the different packages, or exactly when (a few month ago ?)...
Reproducible example
library(dplyr)
#>
#> Attachement du package : 'dplyr'
#> Les objets suivants sont masqués depuis 'package:stats':
#>
#> filter, lag
#> Les objets suivants sont masqués depuis 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
library(purrr)
library(furrr)
#> Le chargement a nécessité le package : future
library(sf)
#> Linking to GEOS 3.11.2, GDAL 3.6.2, PROJ 9.2.0; sf_use_s2() is TRUE
plan(multisession, workers = 2)
# create a {sf} layer with 2 polygons
layer <- data.frame(id = 1:2) %>%
mutate(geom = c("POINT(0 0)", "POINT(0 1)")) %>%
st_as_sf(wkt = "geom") %>%
st_buffer(0.5)with ggplot: work with walk but not future_walk
# ggplot and save a map of the layer d for id == i
my_plot <- function(i, d) {
d %>%
filter(id == i) %>%
ggplot() +
geom_sf()
ggsave(paste0("plot_", i, ".png"))
}
layer %>%
pull(id) %>%
walk(my_plot, d = layer)
#> Saving 7 x 5 in image
#> Saving 7 x 5 in image
layer %>%
pull(id) %>%
future_walk(my_plot, d = layer)
#> Error:
#> ℹ In index: 1.
#> Caused by error in `vec_size()`:
#> ! `x` must be a vector, not a <sfc_POLYGON/sfc> object.
#> Backtrace:
#> ▆
#> 1. ├─parallel (local) workRSOCK()
#> 2. │ └─parallel:::workLoop(...)
#> 3. │ └─parallel:::workCommand(master)
#> 4. │ ├─base::tryCatch(...)
#> 5. │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 6. │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 7. │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 8. │ ├─base::tryCatch(...)
#> 9. │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 10. │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 11. │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 12. │ ├─base::do.call(msg$data$fun, msg$data$args, quote = TRUE)
#> 13. │ └─future (local) `<fn>`(...)
#> 14. │ └─base::eval(expr, envir = envir, enclos = enclos)
#> 15. │ └─base::eval(expr, envir = envir, enclos = enclos)
#> 16. ├─base::tryCatch(...)
#> 17. │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 18. │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 19. │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 20. ├─base::withCallingHandlers(...)
#> 21. ├─base::withVisible(...)
#> 22. ├─base::local(...)
#> 23. │ └─base::eval.parent(substitute(eval(quote(expr), envir)))
#> 24. │ └─base::eval(expr, p)
#> 25. │ └─base::eval(expr, p)
#> 26. ├─base::eval(...)
#> 27. │ └─base::eval(...)
#> 28. │ ├─base::withCallingHandlers(...)
#> 29. │ ├─base::do.call(...furrr_map_fn, args)
#> 30. │ └─purrr (local) `<fn>`(.x = 1L, .f = `<fn>`, d = `<sf[,2]>`)
#> 31. │ └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
#> 32. │ ├─purrr:::with_indexed_errors(...)
#> 33. │ │ └─base::withCallingHandlers(...)
#> 34. │ ├─purrr:::call_with_cleanup(...)
#> 35. │ └─.f(.x[[i]], ...)
#> 36. │ └─global ...furrr_fn(...)
#> 37. │ └─d %>% filter(id == i) %>% ggplot()
#> 38. ├─ggplot2::ggplot(.)
#> 39. ├─dplyr::filter(., id == i)
#> 40. ├─dplyr:::filter.data.frame(., id == i)
#> 41. │ ├─dplyr::dplyr_row_slice(.data, loc, preserve = .preserve)
#> 42. │ └─dplyr:::dplyr_row_slice.data.frame(.data, loc, preserve = .preserve)
#> 43. │ ├─dplyr::dplyr_reconstruct(vec_slice(data, i), data)
#> 44. │ │ └─dplyr:::dplyr_new_data_frame(data)
#> 45. │ │ ├─row.names %||% .row_names_info(x, type = 0L)
#> 46. │ │ └─base::.row_names_info(x, type = 0L)
#> 47. │ └─vctrs::vec_slice(data, i)
#> 48. └─vctrs:::stop_scalar_type(`<fn>`(`<s_POLYGO>`), "x", `<fn>`(vec_size()))
#> 49. └─vctrs:::stop_vctrs(...)
#> 50. └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = call)with base plot: work with walk but not future_walk
# plot and save a map of the layer d for id == i
my_plot_base <- function(i, d) {
plot(d[d$id == i, ], main = i)
}
layer %>%
pull(id) %>%
walk(my_plot_base, d = layer)layer %>%
pull(id) %>%
future_walk(my_plot_base, d = layer)
#> Warning in min(x): aucun argument trouvé pour min ; Inf est renvoyé
#> Warning in max(x): aucun argument pour max ; -Inf est renvoyé
#> Error:
#> ℹ In index: 1.
#> Caused by error in `plot.window()`:
#> ! valeurs finies requises pour 'ylim'
#> Backtrace:
#> ▆
#> 1. ├─parallel (local) workRSOCK()
#> 2. │ └─parallel:::workLoop(...)
#> 3. │ └─parallel:::workCommand(master)
#> 4. │ ├─base::tryCatch(...)
#> 5. │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 6. │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 7. │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 8. │ ├─base::tryCatch(...)
#> 9. │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 10. │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 11. │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 12. │ ├─base::do.call(msg$data$fun, msg$data$args, quote = TRUE)
#> 13. │ └─future (local) `<fn>`(...)
#> 14. │ └─base::eval(expr, envir = envir, enclos = enclos)
#> 15. │ └─base::eval(expr, envir = envir, enclos = enclos)
#> 16. ├─base::tryCatch(...)
#> 17. │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 18. │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 19. │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 20. ├─base::withCallingHandlers(...)
#> 21. ├─base::withVisible(...)
#> 22. ├─base::local(...)
#> 23. │ └─base::eval.parent(substitute(eval(quote(expr), envir)))
#> 24. │ └─base::eval(expr, p)
#> 25. │ └─base::eval(expr, p)
#> 26. ├─base::eval(...)
#> 27. │ └─base::eval(...)
#> 28. │ ├─base::withCallingHandlers(...)
#> 29. │ ├─base::do.call(...furrr_map_fn, args)
#> 30. │ └─purrr (local) `<fn>`(.x = 1L, .f = `<fn>`, d = `<sf[,2]>`)
#> 31. │ └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
#> 32. │ ├─purrr:::with_indexed_errors(...)
#> 33. │ │ └─base::withCallingHandlers(...)
#> 34. │ ├─purrr:::call_with_cleanup(...)
#> 35. │ └─.f(.x[[i]], ...)
#> 36. │ └─global ...furrr_fn(...)
#> 37. │ ├─base::plot(d[d$id == i, ], main = i)
#> 38. │ └─graphics:::plot.data.frame(d[d$id == i, ], main = i)
#> 39. │ └─graphics (local) plot2(x, ...)
#> 40. │ ├─base::plot(x[[1L]], x[[2L]], xlab = xlab, ylab = ylab, ...)
#> 41. │ └─graphics::plot.default(...)
#> 42. │ └─graphics (local) localWindow(xlim, ylim, log, asp, ...)
#> 43. │ └─graphics::plot.window(...)
#> 44. └─base::.handleSimpleError(...)
#> 45. └─purrr (local) h(simpleError(msg, call))
#> 46. └─cli::cli_abort(...)
#> 47. └─rlang::abort(...)just displaying is fine
display <- function(i, d) {
print(d[d$id == i, ])
}
layer %>%
pull(id) %>%
future_walk(display, d = layer)
#> id
#> 1 1
#> geom
#> 1 5.000000e-01, 4.993148e-01, 4.972609e-01, 4.938442e-01, 4.890738e-01, 4.829629e-01, 4.755283e-01, 4.667902e-01, 4.567727e-01, 4.455033e-01, 4.330127e-01, 4.193353e-01, 4.045085e-01, 3.885730e-01, 3.715724e-01, 3.535534e-01, 3.345653e-01, 3.146602e-01, 2.938926e-01, 2.723195e-01, 2.500000e-01, 2.269952e-01, 2.033683e-01, 1.791840e-01, 1.545085e-01, 1.294095e-01, 1.039558e-01, 7.821723e-02, 5.226423e-02, 2.616798e-02, 3.061516e-17, -2.616798e-02, -5.226423e-02, -7.821723e-02, -1.039558e-01, -1.294095e-01, -1.545085e-01, -1.791840e-01, -2.033683e-01, -2.269952e-01, -2.500000e-01, -2.723195e-01, -2.938926e-01, -3.146602e-01, -3.345653e-01, -3.535534e-01, -3.715724e-01, -3.885730e-01, -4.045085e-01, -4.193353e-01, -4.330127e-01, -4.455033e-01, -4.567727e-01, -4.667902e-01, -4.755283e-01, -4.829629e-01, -4.890738e-01, -4.938442e-01, -4.972609e-01, -4.993148e-01, -5.000000e-01, -4.993148e-01, -4.972609e-01, -4.938442e-01, -4.890738e-01, -4.829629e-01, -4.755283e-01, -4.667902e-01, -4.567727e-01, -4.455033e-01, -4.330127e-01, -4.193353e-01, -4.045085e-01, -3.885730e-01, -3.715724e-01, -3.535534e-01, -3.345653e-01, -3.146602e-01, -2.938926e-01, -2.723195e-01, -2.500000e-01, -2.269952e-01, -2.033683e-01, -1.791840e-01, -1.545085e-01, -1.294095e-01, -1.039558e-01, -7.821723e-02, -5.226423e-02, -2.616798e-02, -9.184548e-17, 2.616798e-02, 5.226423e-02, 7.821723e-02, 1.039558e-01, 1.294095e-01, 1.545085e-01, 1.791840e-01, 2.033683e-01, 2.269952e-01, 2.500000e-01, 2.723195e-01, 2.938926e-01, 3.146602e-01, 3.345653e-01, 3.535534e-01, 3.715724e-01, 3.885730e-01, 4.045085e-01, 4.193353e-01, 4.330127e-01, 4.455033e-01, 4.567727e-01, 4.667902e-01, 4.755283e-01, 4.829629e-01, 4.890738e-01, 4.938442e-01, 4.972609e-01, 4.993148e-01, 5.000000e-01, 0.000000e+00, -2.616798e-02, -5.226423e-02, -7.821723e-02, -1.039558e-01, -1.294095e-01, -1.545085e-01, -1.791840e-01, -2.033683e-01, -2.269952e-01, -2.500000e-01, -2.723195e-01, -2.938926e-01, -3.146602e-01, -3.345653e-01, -3.535534e-01, -3.715724e-01, -3.885730e-01, -4.045085e-01, -4.193353e-01, -4.330127e-01, -4.455033e-01, -4.567727e-01, -4.667902e-01, -4.755283e-01, -4.829629e-01, -4.890738e-01, -4.938442e-01, -4.972609e-01, -4.993148e-01, -5.000000e-01, -4.993148e-01, -4.972609e-01, -4.938442e-01, -4.890738e-01, -4.829629e-01, -4.755283e-01, -4.667902e-01, -4.567727e-01, -4.455033e-01, -4.330127e-01, -4.193353e-01, -4.045085e-01, -3.885730e-01, -3.715724e-01, -3.535534e-01, -3.345653e-01, -3.146602e-01, -2.938926e-01, -2.723195e-01, -2.500000e-01, -2.269952e-01, -2.033683e-01, -1.791840e-01, -1.545085e-01, -1.294095e-01, -1.039558e-01, -7.821723e-02, -5.226423e-02, -2.616798e-02, -6.123032e-17, 2.616798e-02, 5.226423e-02, 7.821723e-02, 1.039558e-01, 1.294095e-01, 1.545085e-01, 1.791840e-01, 2.033683e-01, 2.269952e-01, 2.500000e-01, 2.723195e-01, 2.938926e-01, 3.146602e-01, 3.345653e-01, 3.535534e-01, 3.715724e-01, 3.885730e-01, 4.045085e-01, 4.193353e-01, 4.330127e-01, 4.455033e-01, 4.567727e-01, 4.667902e-01, 4.755283e-01, 4.829629e-01, 4.890738e-01, 4.938442e-01, 4.972609e-01, 4.993148e-01, 5.000000e-01, 4.993148e-01, 4.972609e-01, 4.938442e-01, 4.890738e-01, 4.829629e-01, 4.755283e-01, 4.667902e-01, 4.567727e-01, 4.455033e-01, 4.330127e-01, 4.193353e-01, 4.045085e-01, 3.885730e-01, 3.715724e-01, 3.535534e-01, 3.345653e-01, 3.146602e-01, 2.938926e-01, 2.723195e-01, 2.500000e-01, 2.269952e-01, 2.033683e-01, 1.791840e-01, 1.545085e-01, 1.294095e-01, 1.039558e-01, 7.821723e-02, 5.226423e-02, 2.616798e-02, 0.000000e+00
#> id
#> 2 2
#> geom
#> 2 5.000000e-01, 4.993148e-01, 4.972609e-01, 4.938442e-01, 4.890738e-01, 4.829629e-01, 4.755283e-01, 4.667902e-01, 4.567727e-01, 4.455033e-01, 4.330127e-01, 4.193353e-01, 4.045085e-01, 3.885730e-01, 3.715724e-01, 3.535534e-01, 3.345653e-01, 3.146602e-01, 2.938926e-01, 2.723195e-01, 2.500000e-01, 2.269952e-01, 2.033683e-01, 1.791840e-01, 1.545085e-01, 1.294095e-01, 1.039558e-01, 7.821723e-02, 5.226423e-02, 2.616798e-02, 3.061516e-17, -2.616798e-02, -5.226423e-02, -7.821723e-02, -1.039558e-01, -1.294095e-01, -1.545085e-01, -1.791840e-01, -2.033683e-01, -2.269952e-01, -2.500000e-01, -2.723195e-01, -2.938926e-01, -3.146602e-01, -3.345653e-01, -3.535534e-01, -3.715724e-01, -3.885730e-01, -4.045085e-01, -4.193353e-01, -4.330127e-01, -4.455033e-01, -4.567727e-01, -4.667902e-01, -4.755283e-01, -4.829629e-01, -4.890738e-01, -4.938442e-01, -4.972609e-01, -4.993148e-01, -5.000000e-01, -4.993148e-01, -4.972609e-01, -4.938442e-01, -4.890738e-01, -4.829629e-01, -4.755283e-01, -4.667902e-01, -4.567727e-01, -4.455033e-01, -4.330127e-01, -4.193353e-01, -4.045085e-01, -3.885730e-01, -3.715724e-01, -3.535534e-01, -3.345653e-01, -3.146602e-01, -2.938926e-01, -2.723195e-01, -2.500000e-01, -2.269952e-01, -2.033683e-01, -1.791840e-01, -1.545085e-01, -1.294095e-01, -1.039558e-01, -7.821723e-02, -5.226423e-02, -2.616798e-02, -9.184548e-17, 2.616798e-02, 5.226423e-02, 7.821723e-02, 1.039558e-01, 1.294095e-01, 1.545085e-01, 1.791840e-01, 2.033683e-01, 2.269952e-01, 2.500000e-01, 2.723195e-01, 2.938926e-01, 3.146602e-01, 3.345653e-01, 3.535534e-01, 3.715724e-01, 3.885730e-01, 4.045085e-01, 4.193353e-01, 4.330127e-01, 4.455033e-01, 4.567727e-01, 4.667902e-01, 4.755283e-01, 4.829629e-01, 4.890738e-01, 4.938442e-01, 4.972609e-01, 4.993148e-01, 5.000000e-01, 1.000000e+00, 9.738320e-01, 9.477358e-01, 9.217828e-01, 8.960442e-01, 8.705905e-01, 8.454915e-01, 8.208160e-01, 7.966317e-01, 7.730048e-01, 7.500000e-01, 7.276805e-01, 7.061074e-01, 6.853398e-01, 6.654347e-01, 6.464466e-01, 6.284276e-01, 6.114270e-01, 5.954915e-01, 5.806647e-01, 5.669873e-01, 5.544967e-01, 5.432273e-01, 5.332098e-01, 5.244717e-01, 5.170371e-01, 5.109262e-01, 5.061558e-01, 5.027391e-01, 5.006852e-01, 5.000000e-01, 5.006852e-01, 5.027391e-01, 5.061558e-01, 5.109262e-01, 5.170371e-01, 5.244717e-01, 5.332098e-01, 5.432273e-01, 5.544967e-01, 5.669873e-01, 5.806647e-01, 5.954915e-01, 6.114270e-01, 6.284276e-01, 6.464466e-01, 6.654347e-01, 6.853398e-01, 7.061074e-01, 7.276805e-01, 7.500000e-01, 7.730048e-01, 7.966317e-01, 8.208160e-01, 8.454915e-01, 8.705905e-01, 8.960442e-01, 9.217828e-01, 9.477358e-01, 9.738320e-01, 1.000000e+00, 1.026168e+00, 1.052264e+00, 1.078217e+00, 1.103956e+00, 1.129410e+00, 1.154508e+00, 1.179184e+00, 1.203368e+00, 1.226995e+00, 1.250000e+00, 1.272320e+00, 1.293893e+00, 1.314660e+00, 1.334565e+00, 1.353553e+00, 1.371572e+00, 1.388573e+00, 1.404508e+00, 1.419335e+00, 1.433013e+00, 1.445503e+00, 1.456773e+00, 1.466790e+00, 1.475528e+00, 1.482963e+00, 1.489074e+00, 1.493844e+00, 1.497261e+00, 1.499315e+00, 1.500000e+00, 1.499315e+00, 1.497261e+00, 1.493844e+00, 1.489074e+00, 1.482963e+00, 1.475528e+00, 1.466790e+00, 1.456773e+00, 1.445503e+00, 1.433013e+00, 1.419335e+00, 1.404508e+00, 1.388573e+00, 1.371572e+00, 1.353553e+00, 1.334565e+00, 1.314660e+00, 1.293893e+00, 1.272320e+00, 1.250000e+00, 1.226995e+00, 1.203368e+00, 1.179184e+00, 1.154508e+00, 1.129410e+00, 1.103956e+00, 1.078217e+00, 1.052264e+00, 1.026168e+00, 1.000000e+00Session info (future and base)
future::futureSessionInfo()
#> *** Package versions
#> future 1.33.0, parallelly 1.36.0, parallel 4.3.1, globals 0.16.2, listenv 0.9.0
#>
#> *** Allocations
#> availableCores():
#> system
#> 12
#> availableWorkers():
#> $system
#> [1] "localhost" "localhost" "localhost" "localhost" "localhost" "localhost"
#> [7] "localhost" "localhost" "localhost" "localhost" "localhost" "localhost"
#>
#> *** Settings
#> - future.plan=<not set>
#> - future.fork.multithreading.enable=<not set>
#> - future.globals.maxSize=<not set>
#> - future.globals.onReference=<not set>
#> - future.resolve.recursive=<not set>
#> - future.rng.onMisuse=<not set>
#> - future.wait.timeout=<not set>
#> - future.wait.interval=<not set>
#> - future.wait.alpha=<not set>
#> - future.startup.script=<not set>
#>
#> *** Backends
#> Number of workers: 2
#> List of future strategies:
#> 1. multisession:
#> - args: function (..., workers = 2, envir = parent.frame())
#> - tweaked: TRUE
#> - call: plan(multisession, workers = 2)
#>
#> *** Basic tests
#> Main R session details:
#> pid r sysname release version nodename machine login user
#> 1 24936 4.3.1 Windows 10 x64 build 19044 host001 x86-64 user001 user001
#> effective_user
#> 1 user001
#> Worker R session details:
#> worker pid r sysname release version nodename machine login
#> 1 1 16300 4.3.1 Windows 10 x64 build 19044 host001 x86-64 user001
#> 2 2 13960 4.3.1 Windows 10 x64 build 19044 host001 x86-64 user001
#> user effective_user
#> 1 user001 user001
#> 2 user001 user001
#> Number of unique worker PIDs: 2 (as expected)Created on 2023-09-04 with reprex v2.0.2
Session info
sessionInfo()
#> R version 4.3.1 (2023-06-16 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19044)
#>
#> Matrix products: default
#>
#>
#> locale:
#> [1] LC_COLLATE=French_France.utf8 LC_CTYPE=French_France.utf8
#> [3] LC_MONETARY=French_France.utf8 LC_NUMERIC=C
#> [5] LC_TIME=French_France.utf8
#>
#> time zone: Europe/Paris
#> tzcode source: internal
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] sf_1.0-14 furrr_0.3.1 future_1.33.0 purrr_1.0.2 ggplot2_3.4.3
#> [6] dplyr_1.1.2
#>
#> loaded via a namespace (and not attached):
#> [1] utf8_1.2.3 generics_0.1.3 xml2_1.3.5 class_7.3-22
#> [5] KernSmooth_2.23-21 listenv_0.9.0 digest_0.6.33 magrittr_2.0.3
#> [9] evaluate_0.21 grid_4.3.1 fastmap_1.1.1 e1071_1.7-13
#> [13] DBI_1.1.3 fansi_1.0.4 scales_1.2.1 codetools_0.2-19
#> [17] textshaping_0.3.6 cli_3.6.1 rlang_1.1.1 units_0.8-3
#> [21] parallelly_1.36.0 munsell_0.5.0 reprex_2.0.2 withr_2.5.0
#> [25] yaml_2.3.7 tools_4.3.1 parallel_4.3.1 colorspace_2.1-0
#> [29] globals_0.16.2 curl_5.0.2 vctrs_0.6.3 R6_2.5.1
#> [33] proxy_0.4-27 lifecycle_1.0.3 classInt_0.4-9 fs_1.6.3
#> [37] ragg_1.2.5 pkgconfig_2.0.3 pillar_1.9.0 gtable_0.3.4
#> [41] glue_1.6.2 Rcpp_1.0.11 systemfonts_1.0.4 highr_0.10
#> [45] xfun_0.40 tibble_3.2.1 tidyselect_1.2.0 rstudioapi_0.15.0
#> [49] knitr_1.43 farver_2.1.1 htmltools_0.5.6 rmarkdown_2.24
#> [53] compiler_4.3.1Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels

