%dofuture% foreach 文件未找到警告

问题描述 投票:0回答:1

尝试让 %dofuture% 工作,但使用以下代码时出现错误。不知道为什么。

library(foreach)
library(doParallel)
library(doFuture)

plan(multisession,workers=availableCores())

# Create a .bat file in your downloads folder called "Example1.bat" including the following:
# @ECHO OFF
# ECHO Such a useful reproducible code...

Folder.Path <- "C:/Users/Insert.Name.Here/Downloads/"
setwd(Folder.Path)
system2("Example1.bat") # this runs as expected
foreach(i=1)%do%{system2(paste0("Example",i,".bat"))} # this runs as expected
foreach(i=1)%dopar%{system2(paste0("Example",i,".bat"))} # this runs as expected
foreach(i=1)%dofuture%{system2(paste0("Example",i,".bat"))} # this returns a warning

这是我使用 %dofuture% 时收到的警告消息

警告信息: 在 system2(paste0("Example", i, ".bat")) 中:找不到“Example1.bat”

r foreach future system2
1个回答
0
投票

感谢 Henrik Bengtsson:操作顺序在这里很重要

第一:

setwd()

第二个:

plan(multisession,workers=availableCores())

如果您执行相反的顺序(如我上面所做的),即首先

plan()
,然后
setwd()
,那么工作人员不会进入新的工作目录。

© www.soinside.com 2019 - 2024. All rights reserved.