Re: [R] variable scope

2012-08-29 Thread Sam Steingold
> * Duncan Murdoch [2012-08-29 10:30:10 -0400]: > > On 29/08/2012 12:50 AM, Sam Steingold wrote: >> > * Duncan Murdoch [2012-08-28 21:06:33 -0400]: >> > >> > On 12-08-28 5:55 PM, Sam Steingold wrote: >> >> >> >> my observation is that gc in R sucks. >> >> (it cannot release small objects). >> >>

Re: [R] variable scope

2012-08-29 Thread Duncan Murdoch
On 29/08/2012 12:50 AM, Sam Steingold wrote: > * Duncan Murdoch [2012-08-28 21:06:33 -0400]: > > On 12-08-28 5:55 PM, Sam Steingold wrote: >>> * R. Michael Weylandt [2012-08-28 13:45:35 -0500]: >>> always you shouldn't need manual garbage collection. >> >> my observation is that gc in R s

Re: [R] variable scope

2012-08-28 Thread Sam Steingold
> * Duncan Murdoch [2012-08-28 21:06:33 -0400]: > > On 12-08-28 5:55 PM, Sam Steingold wrote: >>> * R. Michael Weylandt [2012-08-28 13:45:35 >>> -0500]: >>> always you shouldn't need manual garbage collection. >> >> my observation is that gc in R sucks. >> (it cannot release small objects).

Re: [R] variable scope

2012-08-28 Thread Sam Steingold
> * Jeff Newmiller [2012-08-28 15:21:39 -0700]: > > Sam Steingold wrote: > >>> * R. Michael Weylandt [2012-08-28 >>13:45:35 -0500]: >>> always you shouldn't need manual garbage collection. >> >>my observation is that gc in R sucks. >>(it cannot release small objects). >>this is not specific

Re: [R] variable scope

2012-08-28 Thread Sam Steingold
> * R. Michael Weylandt [2012-08-28 17:30:06 > -0500]: > >> In my experience, the one point I've needed it was after freeing >> multiple very large objects when hitting memory limits. that's what I am doing. >> Rewriting that code to use functions rather than as one long >> imperative slog was

Re: [R] variable scope

2012-08-28 Thread Jeff Newmiller
--- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Sola

Re: [R] variable scope

2012-08-28 Thread Duncan Murdoch
On 12-08-28 5:55 PM, Sam Steingold wrote: * R. Michael Weylandt [2012-08-28 13:45:35 -0500]: always you shouldn't need manual garbage collection. my observation is that gc in R sucks. (it cannot release small objects). this is not specific to R; ocaml suffers too. Sorry, I didn't realize y

Re: [R] variable scope

2012-08-28 Thread R. Michael Weylandt
On Tue, Aug 28, 2012 at 5:13 PM, R. Michael Weylandt wrote: > On Tue, Aug 28, 2012 at 4:55 PM, Sam Steingold wrote: >>> * R. Michael Weylandt [2012-08-28 13:45:35 >>> -0500]: >>> always you shouldn't need manual garbage collection. >> >> my observation is that gc in R sucks. >> (it cannot

Re: [R] variable scope

2012-08-28 Thread R. Michael Weylandt
On Tue, Aug 28, 2012 at 4:55 PM, Sam Steingold wrote: >> * R. Michael Weylandt [2012-08-28 13:45:35 >> -0500]: >> >>> always you shouldn't need manual garbage collection. > > my observation is that gc in R sucks. > (it cannot release small objects). > this is not specific to R; ocaml suffers too

Re: [R] variable scope

2012-08-28 Thread Sam Steingold
> * R. Michael Weylandt [2012-08-28 13:45:35 > -0500]: > >> always you shouldn't need manual garbage collection. my observation is that gc in R sucks. (it cannot release small objects). this is not specific to R; ocaml suffers too. > since a loop doesn't define its own scope like some languages

Re: [R] variable scope

2012-08-28 Thread Duncan Murdoch
On 28/08/2012 2:29 PM, Sam Steingold wrote: At the end of a for loop its variables are still present: for (i in 1:10) { x <- vector(length=1) } ls() will print "i" and "x". this means that at the end of the for loop body I have to write rm(x) gc() is there a more elegant way

Re: [R] variable scope

2012-08-28 Thread Marc Schwartz
On Aug 28, 2012, at 1:29 PM, Sam Steingold wrote: > At the end of a for loop its variables are still present: > > for (i in 1:10) { > x <- vector(length=1) > } > ls() > > will print "i" and "x". > this means that at the end of the for loop body I have to write > > rm(x) > gc() > >

Re: [R] variable scope

2012-08-28 Thread R. Michael Weylandt
On Tue, Aug 28, 2012 at 1:37 PM, R. Michael Weylandt wrote: > On Tue, Aug 28, 2012 at 1:29 PM, Sam Steingold wrote: >> At the end of a for loop its variables are still present: >> >> for (i in 1:10) { >> x <- vector(length=1) >> } >> ls() >> >> will print "i" and "x". >> this means that

Re: [R] variable scope

2012-08-28 Thread Bert Gunter
Perhaps I'm dense, but huh*? -- Bert *e.g. What are you trying to do? R does it's own garbage collection -- why do you think you need it? And, as a general comment which may or may not be applicable, if you create variables in a function they are local only to the function -- they disappear once t

Re: [R] variable scope

2012-08-28 Thread Rui Barradas
Hello, Maybe local(). Continue your example with #?local local(for (i in 1:10) { x <- vector(length=1) }) ls() # not 'i' nor 'x' Hope this helps, Rui Barradas Em 28-08-2012 19:29, Sam Steingold escreveu: At the end of a for loop its variables are still present: for (i in 1:10) {

Re: [R] variable scope

2012-08-28 Thread R. Michael Weylandt
On Tue, Aug 28, 2012 at 1:29 PM, Sam Steingold wrote: > At the end of a for loop its variables are still present: > > for (i in 1:10) { > x <- vector(length=1) > } > ls() > > will print "i" and "x". > this means that at the end of the for loop body I have to write > > rm(x) > gc() >

Re: [R] variable scope for deltavar function from emdbook

2011-10-13 Thread Uwe Ligges
This is R, not S-Plus. In the first two lines you have expr <- as.expression(substitute(fun)) nvals <- length(eval(expr, envir = as.list(meanval))) Simplified example: y <- 0 fn1 <- function(){ y <- 1 fn1sub <- function() print(y) fn1sub() } fn2sub <- function() print(y) fn2 <- fun

Re: [R] variable scope for deltavar function from emdbook

2011-10-11 Thread Ben Bolker
adad gmx.at> writes: > Working example: > -- > library("emdbook") > > fn <- function() > { > browser() > y <- 2 > print(deltavar(y*b2, meanval=c(b2=3), Sigma=1) ) > } > > x <- 2 > print(deltavar(x*b1, meanval=c(b1=3), Sigma=1) ) > y<-3 > > fn() > >

Re: [R] Variable scope in functions - best practices

2011-07-25 Thread Dieter Menne
Noah Silverman wrote: > > > I have several "global" variables that I want to change with a given > function. (The variable has a different value after the function is > called.) > > Berend Hasselman wrote: > > > Maybe this helps > > ?`<<-` > It helps to get the job done, but the OP aske

Re: [R] Variable scope in functions - best practices

2011-07-24 Thread Thomas Lumley
On Mon, Jul 25, 2011 at 4:14 AM, Noah Silverman wrote: > Hi, > > I'm working on coding some more complex things in R and have need to break > much of the logic into functions. > > I have several "global" variables that I want to change with a given > function.  (The variable has a different valu

Re: [R] Variable scope in functions - best practices

2011-07-24 Thread Enrico Schumann
Hi Noah, you could assign your "global variables" into an environment. Then make it the environment of your function, and use the `<<-` operator (or 'assign'). An example: > myData <- new.env() > myData$i <- 0 > iPlusOne <- function() i <<- i+1 > environment(iPlusOne) <- myData > ls() [1] "iPlu

Re: [R] Variable scope in functions - best practices

2011-07-24 Thread Berend Hasselman
Noah Silverman wrote: > > Hi, > > I'm working on coding some more complex things in R and have need to break > much of the logic into functions. > > I have several "global" variables that I want to change with a given > function. (The variable has a different value after the function is > call

Re: [R] Variable scope R 2.6.1

2008-01-03 Thread Deepayan Sarkar
On 1/2/08, John Fox <[EMAIL PROTECTED]> wrote: > Dear Stefan, > > I don't think that your question was answered. > > If you invoke the formula method for splom(), then your function works; that > is, you can use > > splom(~as.data.frame(rbind(data, outliers)), . . . . > > It looks to me as

Re: [R] Variable scope R 2.6.1

2008-01-02 Thread John Fox
Dear Stefan, I don't think that your question was answered. If you invoke the formula method for splom(), then your function works; that is, you can use splom(~as.data.frame(rbind(data, outliers)), . . . . It looks to me as if this is a scoping problem produced by the way in which splom