I would like to do some 2-dimensional walks using strings of characters by assigning different values to each character. I was planning to ‘pop’ the first character of a string, use it, and repeat for the rest of the string.
How can I achieve something like this?
x <- 'hello stackoverflow'
I’d like to be able to do something like this:
a <- x.pop[1]
print(a)
'h'
print(x)
'ello stackoverflow'
See
?substring.The idea of having a
popmethod that both returns a value and has a side effect of updating the data stored inxis very much a concept from object-oriented programming. So rather than defining apopfunction to operate on character vectors, we can make a reference class with apopmethod.