In R, I'd like to retrieve a list of global variables at the end of my script and iterate over them. Here is my code
#declare a few sample variables
a<-10
b<-"Hello world"
c<-data.frame()
#get all global variables in script and iterate over them
myGlobals<-objects()
for(i in myGlobals){
print(typeof(i)) #prints 'character'
}
My problem is that typeof(i)
always returns character
even though variable a
and c
are not character variables. How can I get the original type of variable inside the for loop?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…