[R] function output

Duncan Murdoch murdoch at stats.uwo.ca
Thu Aug 5 23:07:15 CEST 2004

On Thu, 05 Aug 2004 14:24:57 +0100, "Luis Rideau Cruz" <Luisr at frs.fo>
wrote :

>I have the next function :
>...... is just a sequence of SQL selects.
>But when I try to call the objects created from the select they do not seem to have been created.
>I checked with ls() and they actually do not exist.
>What is the problem?

R passes arguments by value, so the channel that got changed by this
call is a local copy, the change doesn't affect whatever you passed in
to the function.

It's best (from a long-term maintenance point of view) to try to write
your functions without side effects; they should return values, rather
than changing things outside of themselves.  Then when you use them
you make use of what comes out.

If you really want side effects, then investigate the <<- version of
assignment, but study carefully exactly what it does, and be prepared
for it to do something else entirely when you port your code to

Duncan Murdoch

More information about the R-help mailing list