Unfortunately, it was premature. It turns out that the index variable is saved after the for() loop. Heck.
Hm! I already have a function that replaces an arbitrary string in a function with the contents of a variable:
replaceincall <- function(xx,from,to){ # from is a string, to is a name if(is.name(xx)){ ifelse(as.character(xx)==from,return(to),return(xx)); } else { if(is.call(xx)) { oo <- lapply(as.list(xx),function(yy) replaceincall(yy,from,to)); return(as.call(oo)); } else { return(xx); } } }
In my overloaded function <<- I also already extract a list of names from sys.call() that do not correspond to the functions. This means that they are some kind of variable. All I have to do is find those that are not in ls(.GlobalEnv) , and they should be those that are index variables, and they should be replaced with their values ββin the log entry (using the function above) .
Now it can catch and replace stuff besides loops ... but maybe it's good, because, regardless of the reason the variable is not in .GlobalEnv , it is still a dynamic variable and therefore someday, when I look through a magazine Iβm going to wonder how to restore it if I donβt fix its value right now.
Does anyone see flaws in this reasoning?
source share