Sven Johansson
Sven Johansson

Reputation: 11

How run a script refering to an externaly stored script in R?

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?

Upvotes: 0

Views: 67

Answers (1)

Tami
Tami

Reputation: 133

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.

Upvotes: 1

Related Questions