有没有办法将在一台计算机上生成的 R 模型导入到另一台计算机上的 R 中?

Is there a way to import an R model generated in one computer to R on another computer?

我总共有7个训练模型。所有这些都是使用 caret::train 函数创建的。 其中 5 个是在一台笔记本电脑 (Mac) 中用 R 生成的,而另外 2 个是在另一台笔记本电脑 (PC) 中用 R 生成的。我需要输出图表。在此之前,我需要使用 caret::resamples 函数来生成结果。这意味着我需要在同一环境中使用所有 7 个模型。有没有我可以编写的代码来做到这一点?

实际上,根据 Axeman 的评论,您可以使用 saveRDS(model, "model.rds")model <- readRDS("model.rds"),但您不需要使用 .RData 来使用 .rds 文件。您只需在脚本中添加代码行即可!

您可以对环境中的每个模型执行此操作:

saveRDS(model1, "model1.rds")
saveRDS(model2, "model2.rds")

等等,然后传输到另一台你喜欢的电脑上,然后阅读:

model1 <- readRDS("model1.rds")
model2 <- readRDS("model2.rds")