R/runRfocal.R

Defines functions runRcode

#Execute the R-code strings in desired order by way of runidx

#TODO
# strnum not currently used here, but keep in case of future capability.
runRcode <- function(retcode, retidx, strnum, fenv, saveit) {
#here  the loop that actually executes the R code as directed by indices.
assign('runidx', 1, envir = fenv)
# stop when idx > number of rows
# retidx[,] is line number; retidx[,2] is the next line nbr to go to 
runseq <- NULL

 while (runidx <= max(retidx[,1]) ) {
 	for(jline in 1:length(retcode[[runidx]])) {
	 	thisLine <- retcode[[runidx]][[jline]]
	# diagnostic
		runseq <- c(runseq,runidx)
# if  'quitquit' (from funQUIT), break out of loop but still do the stuff after
		if(identical('quitquit', retcode[runidx])){
			runidx <- max(retidx[,1]) + 1
			break
		} 
	  	nextidx <- runidx + 1 
	#; then the if() below checks for that equivalence 
# no current use for what runDO or runASK returns, but keep them returning
# stuff in case I change my mind. 
		gotback <- eval(parse(text = thisLine))
# keep this for the general case of  standalone GOTO (or IF) output
# only those lines will change the value of nextidx when parsed.
		if(!(runidx == nextidx -1 ) ) {
				runidx <<- nextidx 
		} else{
			# no 'jumps' happening
			runidx <<- runidx + 1
		}
	} # end of for jline loop 
}  # end of execution while loop
# diagnostic
if(saveit) {
	write(runseq, file = 'runseq.txt',append = TRUE)
}
thevars <- ls(envir = fenv,all.names=TRUE)
return(unique(thevars))
}

Try the rFocal package in your browser

Any scripts or data that you put into this service are public.

rFocal documentation built on June 8, 2025, 1:09 p.m.