[R] variable scope

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Wed Aug 29 00:21:39 CEST 2012


---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

Sam Steingold <sds at gnu.org> wrote:

>> * R. Michael Weylandt <zvpunry.jrlynaqg at tznvy.pbz> [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.

Algorithms that work on small objects suck, to.  Vectorize, vectorize, vectorize. Then you won't worry about these limitations.

>> since a loop doesn't define its own scope like some languages (a
>> practice that always seemed strange to me),
>
>every level of indentation has its own scope.
>seems reasonable.

reasonable... to you. To me, as well, but the scoping in R has certain advantages for ad-hoc analyses, so leave your grumpy preconceptions behind and learn about environments and their parent environments.

>> The other answer is to use functions / apply statements like the good
>> lord and John Chambers intended :-)
>
>so explicit loops are "deprecated" in some sense?

Notice the emoticon. c.f. comments above on vectorizing. Loops that should be vectorized are strongly discouraged.  Apply functions do looping tasks like for loops, and have similar inefficiencies compared to vectorized code. However, they involve functions, and since any function, anonymous or named, comes with a new environment, your comfort level of scoping should be appeased.

>thanks for your kind and informative reply!
>-- 
>Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X
>11.0.11103000
>http://www.childpsy.net/ http://ffii.org http://mideasttruth.com
>http://think-israel.org http://pmw.org.il http://honestreporting.com
>Computers are like air conditioners: they don't work with open windows!
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list