I have a script of R which takes other scripts of R and manipulates them in such a way, and also executes their code. My script uses some variables (obviously), and when the other scripts use a common variable name, I get in a mess. I wish I could execute the other script like in a capsule, such that the coinciding variables do not affect each other.
I have been reading about environments, and have made a lot of trials, but I don't catch their real meaning.
Example:
script1.txt
___________
i=sample(10:20,1)
script2.txt
___________
i=sample(10:20,1)
myscript.txt
___________
other.script = c("script1.txt", "script2.txt")
for( i in 1:2 ) {
source(other.script[i])
}
i==2
I wish each variable "i" does its duty without affecting the other ones (specially the one in myscript, I don't care much about the other ones).