3

How do I set the working directory relative to the path of the R file open inside RStudio?

How this question is different from the others on this topic:

  • here The source command is only part of the answer, and I am not using a package. I would like to use default R, not the R script package.
  • here didnt work for me on Win7 x64
  • here I dont want to set it permanently to the same place.
Community
  • 1
  • 1
Rilcon42
  • 9,584
  • 18
  • 83
  • 167
  • What is “the open R file”? This isn’t a concept that R supports. However, I’ve had to implement something like this for my package [‹modules›](https://github.com/klmr/modules), and the [solution is quite tricky](https://github.com/klmr/modules/blob/51e12165494257df3c79d7b0babcc4c89c012964/R/module_cache.r#L67-L98). Depending on your use-case, my answer would be: use ‹modules›. – Konrad Rudolph Oct 05 '15 at 14:50
  • You mean that when you open a file, R doesnt store the path somewhere? I am trying to get that path. – Rilcon42 Oct 05 '15 at 14:52
  • “when you open a file” — **how**? – Konrad Rudolph Oct 05 '15 at 14:53
  • By clicking the .R script file. In my case it opens by default in RStudio – Rilcon42 Oct 05 '15 at 14:57
  • 2
    Please be explicit! R is a programming language, it has no concept of clicking on a file. So you opening a file in RStudio. That doesn’t open any file in R, it opens it in *RStudio*, that’s very different. – Konrad Rudolph Oct 05 '15 at 15:02
  • I always thought of RStudio as a GUI wrapper on top of R, based on your comment I am assuming this is not the case? – Rilcon42 Oct 05 '15 at 15:22
  • 1
    No, this is not the case. RStudio is and IDE that happens to be optimized for R. But you can use many other IDEs, e.g. Eclipse or Emacs. R itself is a language and has no conception of the IDE you run it in. – Andrie Oct 08 '15 at 18:15

0 Answers0