Skip to content

foeach()%dofuture% can't find .bat file #730

Answered by HenrikBengtsson
Maize-Blue asked this question in Q&A
Discussion options

You must be logged in to vote

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.

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 i), so I would do something like:

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% {
 …

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@Maize-Blue
Comment options

@HenrikBengtsson
Comment options

Answer selected by Maize-Blue
Comment options

You must be logged in to vote
1 reply
@HenrikBengtsson
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants