Skip to content

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

@elgabbas

Description

@elgabbas

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions