[R] Output args?

Bill Venables Bill.Venables at cmis.csiro.au
Sat Jun 10 05:23:04 CEST 2000


At 08:48 AM 6/9/00 -0400, Ben Bolker wrote:
>
>You may want to look at the help for "assign", or, as a shortcut, try
>the "<<-" version of assignment:
>
>> foo <- function() { a <- 1 }
>> foo()
>> a
>Error: Object "a" not found
>> foo <- function() {  a <<- 1 }
>> foo()
>> a
>[1] 1
>
>Note that this kind of question will eventually lead you into the thick
>of issues like environments, scoping, closures, etc. ... but for simple
>global assignment I think "<<-" is what you need.

.. but be sure to wear steel-capped boots.  This is a quick recipe for
shooting yourself in the foot or, worse, shooting someone *else* in the
foot who happens to use your software.

This warning has been said before but I think it should be voiced *every*
time someone brings up superassignment.  If you think you need "<<-" almost
certainly you don't, and you are doing something dangerous or at least unwise.

Leaving aside the dangerous aspect of this kind of assignment, there is an
even more fundamental and specific objection.  Using superassignment
habitually, as some users seem to do, encourages you to think of R
functions as macros and not as true functions at all, so you are using the
R environment as you would something rather primitive, like Glim.  You can
lose a lot of power and elegance that way and it is a particularly
insidious pit trap from which some people never manage to escape.

Superassignment?  Just say "No".

Bill Venables.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list