Default working directory of jobs within a project

I really like the Jobs tab that has been in the preview release for a while now, and use it frequently, for example when fitting models using brms. However, one thing is really bothering me about its use. When in a project, selecting a script for a job (either in the jobs tab or through "source as local job") the working directory is always set to the directory of the script. However, when running the script normally, the default working directory is the directory of the project you are working in. This means that one can't simply run a script as a job without altering it, or manually changing the working directory in the jobs dialogue every time a job is started.

I find it really intuitive that the behavior between "normal" sourcing or "jobs" sourcing of a file does not work the same by default.

Would love to see the project being respected by jobs.


That's a good idea! There are many people however who write all their scripts with the presumption that the script's parent folder is its working path (even when working in projects). So I think that using the project folder by default is also going to frustrate some users.

Here's one approach that might work:

  • When in a project, check the current working directory when starting a job. If the working directory is a parent of the script being run, default to the working directory.
  • When not in a project, or when the script is not in a parent of the current directory, default to the script's directory.
  • Remember the directory used when running a script, and default to that directory the next time the script is run.

What do you think?


That seems good, your first bullet should solve the problem for me.

Ok, but if they do so presumably they are changing their working directory in their script? Or am missing something about how projects work?

Do you mean the other way around? The current directory is not a parent of the directory script that the script is in?

1 Like

I actually have one additional suggestion, if I may. After a job completes (or fails) it would be great to have a button somewhere to quickly restart/retry without a dialog.


Perhaps unrelated, but maybe comparable for interest, I've noticed a similar difference between working in R Markdown (.Rmd) files vs regular R script (.R) files. If I have one of each in a subdirectory of a project, the .Rmd file treats paths as relative to that subdirectory (that is, relative to where the file is located) while the .R file treats paths as relative to the project. Simply running getwd() in each is sufficient to demonstrate the difference.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.