0

I am looking for a way to run a script with one part of the script stored in a separate file. Like a "normal" script but with one part of the script referring to an external script.

The script stored in a separate file will be generic to several scripts and will be regularly updated, and that is the reason for keeping this part of the script separate.

I have not found anything about how to solve this. Maybe someone else has a solution to this?

amonk
  • 1,769
  • 2
  • 18
  • 27
  • have you tried to `?source` the "external" script? – talat Jul 18 '17 at 07:58
  • just like @docendodiscimus said, `source` is the best option and you could use something like [this](https://stackoverflow.com/a/10070476/6779509) to trigger source at regular intervals – parth Jul 18 '17 at 08:26

1 Answers1

1

It seems you're looking for

source("[file location]")

Be aware that this will automatically run the entire script in that file location, so be aware of that with regards to which names you give objects in that script and the other script you're working with (e.g. if you open a dataframe in your current script and not in the external script, but you're working with that dataframe in the external script too, the name needs to be the same).

Alternatively, you could write the external script in a way that it is loaded into your workspace as a formula, so that you can refer to that formula in the 'current'script.

Tami
  • 133
  • 8
  • Thanks for all help @Tamar V. but I don´t get it working. I´m running this script source("[C:/Users/sven.johansson/Documents/test_datatvatt.r]") Any clue? – Sven Johansson Jul 18 '17 at 09:24
  • 1
    remove the brackets – ChrKoenig Jul 18 '17 at 09:32
  • Still dosen´t work. Do I need to save/prepare the script in any way to make it work? – Sven Johansson Jul 18 '17 at 11:05
  • when you say doesn't work, make sure you include the error along with your question – amonk Jul 18 '17 at 12:44
  • @SvenJohansson: Yes, sorry, it is without the brackets. `source("C:/Users/sven.johansson/Documents/test_datatvatt.r​")` Did you make sure that the file name is completely correct with regards to the capital and small letters? Otherwise it will not work. The script just needs to be saved to that location and then it should work. It will run the script from start till end. What error do you get? – Tami Jul 19 '17 at 07:06