There is a crude implementation of
stacks in 'S Poetry' (available on
www.burns-stat.com). I haven't looked
at it, but I'd guess that code would
work in R as well.
On 04/01/2012 21:22, Tom Roche wrote:
summary: Specifically, how does one do stack/FIFO operations in R?
Generally, how does one
William Dunlap Wed, 4 Jan 2012 22:54:41 +
R functions [can] use their enclosing environments to save state.
Aha!
makeStack - function () {
stack - list()
list(pop = function() {
if (length(stack) == 0) { # get from an enclosing env.
retval - NULL
} else {
On 01/05/2012 09:18 AM, Tom Roche wrote:
William Dunlap Wed, 4 Jan 2012 22:54:41 +
R functions [can] use their enclosing environments to save state.
Aha!
makeStack- function () {
stack- list()
list(pop = function() {
if (length(stack) == 0) { # get from an enclosing env.
Thanks for the improvements. The main point in
my original post was that altering the arguments
of a function is a really bad thing to do in R
(except when using replacement functions). A
function that alters other objects in the caller's
environment is also really bad. By bad I mean
that such
summary: Specifically, how does one do stack/FIFO operations in R?
Generally, how does one code functions with side effects in R?
details:
I have been a coder for years, mostly using C-like semantics (e.g.,
Java). I am now trying to become a scientist, and to use R, but I don't
yet have the
do s[1] and s[-1] do what you're looking for?
those are just to display... if you want to change s, you need to reassign
it or fiddle with namespacing. however, I'd say it is better to write R
code as though data structures are immutable until you explicitly re-assign
them rather than trying to
R functions should not alter their arguments,
except for 'replacement' functions that are called on
the left side of an assignment operators (e.g., x[1]-10
calls the replacement function `[-`).
R functions cam use their enclosing environments to save
state. E.g., the following makeStack function
7 matches
Mail list logo