[R] Writing a workable function
Bill Venables
William.Venables at cmis.CSIRO.AU
Thu Aug 17 00:42:26 CEST 2000
Peter Dalgaard speculates:
>
> Hmm. Perhaps that is a little too pessimistic... Sometimes one just
> need to provide a little information at the right spot to make things
> click into place. In the present case the relevant point would seem
> to be that the result of an expression is not printed during function
> evaluations,
Actually, no, that's not quite the root of the problem, although that
was a peripheral aspect of it. If you look again at the example you
will see that the person was expecting that a local object generated
within a function would exist outside the function as a permanent
variable. In other words that the function would behave just like a
macro in other languages. This is the kind of misconception that is
classically very hard (in my limited experience) to turn around.
People actually *like* working with macros, strange as it may seem.
> but it would be nice also to have an example of why this
> is so - I'd go looking for an example of the kind
>
> for (i in 1:1000) f(x)
>
> where f(x) is used for side effects but also has a visible value,
> which just isn't needed here. Such examples are not all that easy to
> come up with, but maybe it suffices to remind people that since every
> function has a value, one would have to invisible()ify it in every
> single user-written function to avoid having code like the above
> spewing out 1000 lines or more of garbage.
Yes, this is a point, but in this case the problem was more
fundamental.
>
> > I'd say go ahead and have a go by all means, but be careful in what
> > you write as it is a very tricky and sensitive area.
>
> Yes. The FAQ may not be the most obvious target, though. Recently,
> when someone got baffled by the behaviour of source(), it did cross my
> mind that maybe the section on that in the R-intro document could do
> with a couple of words on echo=TRUE. So perhaps R-intro would be a
> more natural place for this stuff too.
No real argument with any of these suggestions, but I do think the
problem is much deeper in this case.
Bill.
--
Bill Venables, Statistician, CMIS Environmetrics Project
CSIRO Marine Labs, PO Box 120, Cleveland, Qld, AUSTRALIA. 4163
Tel: +61 7 3826 7251 Email: Bill.Venables at cmis.csiro.au
Fax: +61 7 3826 7304 http://www.cmis.csiro.au/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