small ggplot object (1 mb) turns into 7 gigabyte .Rdata object when saved

房东的猫 提交于 2019-11-30 23:29:49

I stumbled upon this problem as well. This is indeed related to the environment. If you want to save your plots as an Rdata file, then you should be creating a new environment inside the function that is generating your plot, so that the complete environment doesn't get saved. Example:

makePlot <- function(plot.data){
  env <- new.env(parent = globalenv())
  env$subset <- subset 

  my.plot <- with(env, {
    my.plot <- ggplot(plot.data, ...) 
    return(my.plot)
  })

  return(my.plot)
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!