0

SO i want to execute a R script as an executable file, so I followed this tutorial. http://www.r-datacollection.com/blog/Making-R-files-executable/

And then configured it so that it would always open with the same program and so on.

Now the problem is that when I create the test file they provide, everything works fine, but as soon as i introduce a code such as

workd=dirname(rstudioapi::getSourceEditorContext()$path)

the executing black panel closes down.

Any ideas why that is?

Adrian Mnc
  • 67
  • 10

1 Answers1

0

My guess is that since you are not running RStudio, but rather R on its own, rstudioapi::* calls will fail. It looks like you want to get the system path of your script, the here package can help you with that. Alternatively you could avoid using absolute paths and only use relative paths.

Till
  • 3,845
  • 1
  • 11
  • 18
  • There is a script here that will find the path of the current file: gist.github.com/jasonsychau/ff6bc78a33bf3fd1c6bd4fa78bbf42e7 – G. Grothendieck May 19 '21 at 16:31
  • There's a "highly active question" that addresses this: https://stackoverflow.com/questions/1815606/determine-path-of-the-executing-script and a package "this.path" – IRTFM May 19 '21 at 17:05