Changing WD in RMarkdown

124 views Asked by At

My R Markdown script was running well until I had to access documents from another WD than my RMarkdown-file. I tried to change the WD. But it doesn't take it. I might access documents from different folder during my R Markdown Document. How can I be more flexible without coping my files into R Markdown folders? (that would be wasting space!)

Is this the right command?

knitr::opts_knit$set(root.dir = "C:/Users/Nadine/OneDrive/ZID_Kurse/Einführung/Kursmaterial")

And do I need to put it in the beginning of the document??? It just halts at the chunk with setWD() command.

Cheers, Nadine

1

There are 1 answers

1
Sef On BEST ANSWER

You probably do not need to change the working directory; just explain where to find the files relative to the project working directory. You can use an absolute path to the files on the filesystem, e.g.

list.files("C:/projects/another_project/data/")

Or you may try to use relative paths to navigate to files through the parent directory. e.g.

list.files("../another_project/data/")