This returns a list of all variables in the functions environment:
executeToy <-function(time){
X = 2+time
W = 2
mget(ls())
}
executeToy(1:3)
#$time
#[1] 1 2 3
#
#$W
#[1] 2
#
#$X
#[1] 3 4 5
However, from your comments I believe the browser
function (which steps through an expression, i.e., is usually used for debugging) would be more useful to you.
Example:
executeToy <-function(time){
browser()
X = 2+time
W = 2
X
}
Then call the function:
> executeToy(1:3)
Called from: executeToy(1:3)
Browse[1]> time
[1] 1 2 3
Browse[1]> n
debug at #3: X = 2 + time
Browse[2]> n
debug at #4: W = 2
Browse[2]> X
[1] 3 4 5
Browse[2]> n
debug at #5: X
Browse[2]> W
[1] 2
Browse[2]> n
[1] 3 4 5