在 R 中保存并重新加载 'list' 对象

Save and reload a 'list' object in R

我正在尝试将我通过一些努力手动创建的列表对象保存为 list 格式的内容,以便我可以相当快地返回参考。 保存的对象应该能够作为 list 而不是 df 或任何东西加载回来。

下面是我的列表对象的一部分:

citations <- list(
as.integer(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 111)),
as.integer(c(2, 3, 4, 5, 6, 7, 8, 9, 10, 111)),
as.integer(c(1, 3, 4, 5, 6, 7, 8, 9, 10, 111)),
as.integer(111),
as.integer(111),
as.integer(111),
as.integer(111),
as.integer(111),
as.integer(111),
as.integer(111),
as.integer(111),
as.integer(6),
integer(0),
as.integer(c(14, 15, 16, 17, 18, 19, 20, 21, 22, 23))
)

我引用了 and a much earlier one on nabble,他们建议简单地使用 saveload,但我无法弄清楚这是如何工作的,每当我应用 save() 函数在 list 对象上并为其指定了一个 R 对象,我总是收到一条错误消息。

save(citations, "/~citations.Rdata")
Error in save(citations, "~/citations.Rdata") : object ‘~/citations.Rdata’ not found

只是不知道是否需要其他函数调用。

您的选择是:

  • base::save 并加载
  • base::saveRDS 并读取 RDS
  • rlist::list.save 和 list.load