nxt: Next Statement

Description Usage Details Author(s) See Also Examples

View source: R/revisit.R

Description

Run the current line of code in rvenv$currcode as indicated by the program counter rvenv$pc.

Usage

1
nxt()

Details

This function executes the current line of code in rvenv$currcode as indicated by the program counter rvenv$pc. After execution, rvenv$pc will be incremented to point to the next line.

A restriction is that the line being executed cannot contain one of the starting or ending braces of a function, loop, or conditional block (such as an if or else clause) and not the other. This is because the line is executed as an independent block of code. If it contains only one of the opening and closing braces of a function, loop, or conditional block, it will not by syntactically valid. The use of nxt, along with the more general runb, can be seen by running the following sample program:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
 1  pnum <- function(n){
 2     print(paste("call",n))
 3  }
 4  for (i in 1:3){
 5     pnum(i)
 6  }
 7  if (i == 3){
 8     print("i == 3")
 9  }
10  pnum(4)
11  print("done")

Because of the restrictions, runb must be used to run through line 9. That's because all of those lines except for 2, 5, and 8 contain one of an opening or closing brace but not the other. However, nxt cannot be used to run those lines because there is no standard way to get the program pointer rvenv$pc to point at any of them. However, nxt can be used to execute the last two statements as shown in the following test run that uses the smallest possible steps to step through the entire program:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
> runb(throughline = 3)
> runb(startline = 4,throughline = 6)
[1] "call 1"
[1] "call 2"
[1] "call 3"
> runb(7,9)
[1] "i == 3"
> nxt()
[1] "call 4"
> nxt()
[1] "done"
>

As can be seen, nxt was used to execute the last two statements and the expected result was output in both cases.

Author(s)

Norm Matloff

See Also

edt
loadb
makebranch0
runb
rvinit
saveb

Examples

1
nxt()

matloff/revisit documentation built on May 4, 2019, 4:23 p.m.