Displaying 1 result from an estimated 1 matches for "vector_arg".
2012 Jan 04
3
[newbie] stack operations, or functions with side effects (or both)
...a stack--or, really, just a pop(...) such that
* s <- c(1:5)
* print(s)
[1] 1 2 3 4 5
* pop(s)
[1] 1
* print(s)
[1] 2 3 4 5
but in fact I get
> pop(s)
Error: could not find function "pop"
and Rseek'ing finds me nothing. When I try to write pop(...) I get
pop1 <- function(vector_arg) {
+ length(vector_arg) -> lv
+ vector_arg[1] -> ret
+ vector_arg <<- vector_arg[2:lv]
+ ret
+ }
>
> pop1(s)
[1] 1
> print(s)
[1] 1 2 3 4 5
i.e., no side effect on the argument
pop2 <- function(vector_arg) {
+ length(vector_arg) -> lv
+ vector_arg[1] ->...