Add another Path to current Search Path

Can I add another path to the current search directory?
I can call another script with source("file1.R") and another script in another "sibling" folder with source("..\\otherdir\\file2.R).

I think of something like "addwd("..\\otherdir\\")" to call file2.R with source("file2.R").
I don't think this would lead to too much ambiguity since the working directory is always chosen first.

Not sure I completely follow what you are trying to do. However, if you're trying to temporarily change the working directory to the folder where file2.R is located before it is sourced, you can use the chdir = TRUE argument.

withr::with_dir() ?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

with_dir is maybe the cleanest solution! Thx!

code:

    old <- setwd(dir = new)
    on.exit(setwd(old))
    force(code)