I am running a program that needs to do a task for iterations 1 to 100, then quit and start again and execute for iteration 101 to 200, etc. I thought I would accomplish this by sourcing the program and passing in the values. In my calling program I have
GlobVar1<-1:100
GlobVar2<-101:200
GlobVar3<-201:300
GlobVal<-2
source("C:/Users/JSparks/Documents/testreceiveargs.R")
and in the program C:/Users/JSparks/Documents/testreceiveargs.R
I have
for (i in (1:2))
{
print(GlobVar3[i])
}
Which works fine (output is 201, 202). Or
for (i in (1:2))
{
print(get(paste0("GlobVar",GlobVal)))
}
Which gives output [1] 101 102 103 etc.
But I need to be able to control the values of the looping variable in the new program, but when I try
for (i in (1:2))
{
print(get(paste0("GlobVar",GlobVal,"[i]")))
}
It errors out with message Error in get(paste0("GlobVar", GlobVal, "[i]")) : object 'GlobVar2[i]' not found
How can I combine the paste and the get to get the values that I need, which in this case would be 101, 102. Help would be most appreciated.