-
-
Notifications
You must be signed in to change notification settings - Fork 879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing working directory will impact the location of output #38
Comments
This is expected. It is a bad idea to use |
I see. I'm running tools from the command line which require to be in a I could imagine another example, where sourcing files from different maybe this kind of operation could be enclosed in make sure you don't produce a graphsetwd(owd) So, I understand this won't be possible in knitr. Thanks anyway for the 2011/12/5 Yihui Xie <
|
You are right. It is a good practice to always restore the working directory after you are done with the computation. I just did not realize why there could be a demand on |
My two cents: you should not be changing working directories in the middle of a project. Changing working directory should almost never be done automatically - it's a UI operation because when you set a working directory, you're saying, I'm now working on this project. |
While I understand your point, and with all the respect I have for your Indeed, I could see a workaround like wraping these setwd() in a function : The root of the problem is a program I'm using which outputs files in the Etienne 2011/12/6 hadley wickham <
|
Ah oh, that makes sense. Using system is the one time you do actually need to change the working directory! (I wish it was an option) I use the following function to run chunks of R code in an arbitrary working directory. in_dir <- function(dir, code) {
cur <- getwd()
setwd(dir)
on.exit(setwd(cur))
force(code)
} |
@etiennebr You can use |
I surrender to the ingenuity of |
This working directory issue is challenging... I have a project that is structured like this
If I run chunks in R Studio, then the working directory is "MyProject". I want / expect the working directory to be "MyProject". I want to keep the reports separate so that I can manually manage the large cache folders, and just to keep things organized. This is an ongoing project with interdependent large sets of data, and I don't want to keep everything at the main project level. I don't want to create an absolute path to the data, because I share the project on other machines. Plus, I think that's bad form anyway. Right now I run Any advice? |
This one is kind of tricky, but I would say it is more related to RStudio I found this workaround, I experienced the same problem using 2012/7/24 Gene Leynes <
|
Now this is just genius |
You can use the package option Calling |
Thanks! I tried that unsuccessfully, but I was doing it wrong. |
I tried to set working directory to my project's home directory, using 'root.dir' option, but it didn't work properly. I used an absolute path to project's home directory, not a relative, as above. Is this a problem? This is my report's R Markdown document: https://github.com/abnova/diss-floss/blob/master/analysis/eda-report.Rmd. And this is where I set the option: https://github.com/abnova/diss-floss/blob/master/config/knitr/knitr-setup-global.Rmd. Please take a look and advise. UPDATE: I just tried using a relative path ( |
@abnova - rmarkdown set's the working directory to the location of the Rmd file (separately to knitr). See the following line in render.R (part of the rmarkdown package): https://github.com/rstudio/rmarkdown/blob/28feca137762651c904e05ce119244fc41112fb4/R/render.R#L96 |
@paulboardman Thank you for the comment - I will take a look at that, when I'll get a chance (it's been a while since I was working on that code, but it's good to know nevertheless). Best regards! |
I've been using a function that I wrote to set the project directory There's an example in this Rmd file: I don't love my solution, but it works. On Wed, Feb 25, 2015 at 2:50 PM, Aleksandr Blekh notifications@github.com
|
@geneorama Thank you for the advice, Gene! Will take a look at that. |
Thanks, I would be really interested to hear if it works out for you, or if On Thu, Feb 26, 2015 at 1:27 PM, Aleksandr Blekh notifications@github.com
|
@geneorama I would love to, but it'll be a while until I'll have a chance to get to my software again - currently I'm focusing my efforts on preparing for my Ph.D. dissertation defense (slides, talk, etc.). |
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary. |
This is a problem with sweave as well, but when you change a directory
setwd("aplace")
this will output the figures and the .tex in
~
directory. It can even lead to having stuff really scattered.setwd("here") plot(something) setwd("there") plot(something) ...
It can even bring LyX to crash.
The text was updated successfully, but these errors were encountered: