0
我想知道是否可以并行写入pdf文件。我有很多功能,每个功能都写了很多数字。这是按顺序完成的,需要相当长的时间。R,并行写入pdf
举个简单的例子:
plot1 <- function() plot(c(1, 2, 3, 4, 5), type="o", col="blue")
plot2 <- function() plot(c(5, 4, 3, 2, 1), type="o", col="blue")
pdf("PDFname.pdf", width = 12, height = 10)
plot1()
plot2()
dev.off()
我试图使其平行这样的:
library (parallel)
plots <- list(
plot1 <- function() plot(c(1, 2, 3, 4, 5), type="o", col="blue"),
plot2 <- function() plot(c(5, 4, 3, 2, 1), type="o", col="blue")
)
cl <- makeCluster(2);
pdf("PDFname.pdf", width = 12, height = 10)
clusterApply(cl, plots, function(func) func())
dev.off()
stopCluster(cl)
即使功能并行执行,我得到一个空的PDF文件。
感谢您的任何建议。
感谢您的回复,但我也同时实现的代码,所以我没有看到用parLapply重写它的原因。并感谢您的链接。看起来像是真的不可能 –