Re: [R] [newbie] stack operations, or functions with side effects (or both)

2012-01-05 Thread William Dunlap
anuary 05, 2012 10:38 AM > To: r-help@r-project.org; Tom Roche > Subject: Re: [R] [newbie] stack operations, or functions with side effects > (or both) > > On 01/05/2012 09:18 AM, Tom Roche wrote: > > > > William Dunlap Wed, 4 Jan 2012 22:54:41 + > >> R functio

Re: [R] [newbie] stack operations, or functions with side effects (or both)

2012-01-05 Thread Martin Morgan
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.

Re: [R] [newbie] stack operations, or functions with side effects (or both)

2012-01-05 Thread Tom Roche
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 { >

Re: [R] [newbie] stack operations, or functions with side effects (or both)

2012-01-05 Thread Patrick Burns
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 c

Re: [R] [newbie] stack operations, or functions with side effects (or both)

2012-01-04 Thread William Dunlap
ot; There are various encapsulations of this method in R. See, e.g., "reference classes" or the "proto" package. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] O

Re: [R] [newbie] stack operations, or functions with side effects (or both)

2012-01-04 Thread Justin Haynes
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 de

[R] [newbie] stack operations, or functions with side effects (or both)

2012-01-04 Thread Tom Roche
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 sens