Run different lines from script using source

I'm wondering if I can create a mater r code ( master.R) and call certain lines from different places inside master.R. For example, using the master.R:

source ( "/changes.R")  # only run this script using lines between 1:100
source ( "/changes.R")  # only run this script using lines between 101:200
# end of master.R

Is it possible?
Thanks for your time and interest.

You'd probably be better off with putting whatever your scripts are doing into functions and calling them instead. The way you want to do it might be easy for you to grasp right now, but it'll make a lot more complicated down the line.

I don't know how to proceed as you suggest.
I read in some website that matlab can do what I need.
Runing only certain sections from a code. I thought that was pointless, but now I am needy of that task.

Say you have a script like this:

a <- 2

# line 3
a + a
# line 5

# line 8
# line 10

What you are asking is then in your "main" script, you need to run something between lines 3-5 or between lines 8-10. Is that correct? Or what are you trying to achieve actually?

I'm not a big user of Matlab, but it's unlikely it does something that is not possible with R (or with any other programming language, for that matter).

1 Like

What I need is to run only specific lines from the code named "changes.R" using the source function or similar. I'm always using the master.R script to run everything.
That's my goal.

You can always split the changes.R into multiple files (changes01 / changes 02 ...) and run one after the other if this helps.
Or do you additionally need to run this completely at once?

That's not a plausible option. I need to use just two script files.
master.R and changes.R. I know It's strange what I am asking.
Maybe It isn't possible now, but it will be in the future. :relieved:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.