我正在寻找一种保存一些ggplot
对象以供以后使用的方法。 dput
函数创建一个字符串,该字符串在传递给dget()
时将返回意外的<
错误:
.internal.selfref = <
。通过将.internal.selfref
设置为NULL
,可以很容易地解决此问题。<environment>
。我试图将<environment>
更改为NULL
或environment()
之类的东西,但是它们都不起作用-环境设置不正确,并且返回找不到对象的错误。一些搜索使我进入功能ggedit::dput.ggedit
。但这给了我错误:
# Error in sprintf("%s = %s", item, y) :
# invalid type of argument[2]: 'symbol'
我在想,要么我通过使用dput
函数来设置环境,要么就弄清楚为什么ggedit::dput.ggedit
不起作用...
有什么主意吗?
答案 0 :(得分:0)
不使用dput()
,而是保存ggplot对象以供以后使用,可以将它们另存为.rds
文件(就像任何R对象一样)。
示例:
my_plot <- ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy))
saveRDS(my_plot, "my_plot.rds")
并在另一个会话,另一个脚本等中还原您的对象。
my_plot <- readRDS("my_plot.rds")
答案 1 :(得分:0)