Pass a variable into an R Script and source it

Hi All

I have a 2000 line script. I run it for a single entity which is specified at the start of the script. I have been asked if we could run the script for a second entity. I would like to have an R script that calls the previously mentioned script but changes the entity before sourcing it. I understand i could just put the whole script inside a function but this seems a bit overkill and also incredibly messy.

For example below is the script

entity <- "entity 1"
# Run 2000 line script and produce results

What i would like to do is something like

source_script("entity_1")
source_script("entity_2")

Does anyone have any suggestions on how one would approach this?

Thank you very much for your time

This is known as putting a script inside a function., so I would reconsider your bias against pursuing a functional approach.

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.