foeach()%dofuture% can't find .bat file #730
-
Trying to get %dofuture% to work, but getting an error using the following code. Not sure why.
This is the warning message I get when I use %dofuture% Warning message: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
This happens because the working directory of the parallel workers does not change when you change the working directory in your main R session. My recommendation is to avoid Folder.Path <- "C:/Users/Insert.Name.Here/Downloads/"
res <- foreach(i = 1) %dofuture% {
pathname <- file.path(Folder.Path, paste0("Example",i,".bat"))
system2(pathname)
} Personally, I always try to avoid indices (here library(doFuture)
Folder.Path <- "C:/Users/Insert.Name.Here/Downloads/"
pathnames <- file.path(Folder.Path, paste0("Example", 1:10, ".bat"))
res <- foreach(pathname = pathnames) %dofuture% {
system2(pathname)
} or library(future.apply)
Folder.Path <- "C:/Users/Insert.Name.Here/Downloads/"
pathnames <- file.path(Folder.Path, paste0("Example", 1:10, ".bat"))
res <- lapply(pathnames, function(pathname) {
system2(pathname)
}) BTW, when you use doFuture, there's no need for the doParallel package. |
Beta Was this translation helpful? Give feedback.
-
I tried using the first chunnk above. I'm not getting the desired output and res[[1]] is showing 0
|
Beta Was this translation helpful? Give feedback.
This happens because the working directory of the parallel workers does not change when you change the working directory in your main R session.
My recommendation is to avoid
setwd()
in your scripts, and instead work with the full pathnames, e.g.Personally, I always try to avoid indices (here
i
), so I would do something like: