r-lib / lobstr

Understanding complex R objects with tools similar to str()
https://lobstr.r-lib.org/
Other
303 stars 27 forks source link

Error with `lobstr::obj_size` / `pryr::object_size` when used with a ggplot object created with `geom_spatraster` #74

Closed elgabbas closed 1 month ago

elgabbas commented 3 months ago

Hello, I am getting the following error when using lobstr::obj_size or pryr::object_size with a ggplot object

Error in obj_size_(dots, env, size_node(), size_vector()) : 
  bad binding access

Here is a reprex

library(terra); library(ggplot2); library(tidyterra)
file_path <- system.file("extdata/cyl_temp.tif", package = "tidyterra")
temp_rast <- rast(file_path)
Plot <- ggplot() +
  geom_spatraster(data = temp_rast, aes(fill = tavg_04)) +
  coord_sf(crs = 3857) +
  scale_fill_grass_c(palette = "celsius")

lobstr::obj_size(Plot)             # this gives an error
object.size(Plot)                   # this works
# Without the `geom_spatraster` geometry, the function works
Plot <- ggplot() +
    # geom_spatraster(data = temp_rast, aes(fill = tavg_04)) +
    coord_sf(crs = 3857) +
    scale_fill_grass_c(palette = "celsius")
lobstr::obj_size(Plot)   # this works

It seems that the function can not read the file size of ggplot object when geom_spatraster is used.

hadley commented 1 month ago

Duplicate of #72