[R] Writing a workable function
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Wed Aug 16 10:35:08 CEST 2000
Bill Venables <William.Venables at cmis.csiro.au> writes:
> Ben Bolker writes:
>
> >
> > Perhaps a short description of this issue [functions, return values,
> > assignment, printing intermediate results] could go in the R FAQ? If no
> > one else will, I'd be willing to take a shot at writing it ... I would
> > personally be inclined to give the hint, in a suitably deprecated form,
> > about global assignment, but also to try to clarify the reasons why it's a
> > bad idea.
> >
>
> Unfortunately I don't think a short description is likely to be good
> enough and a long description is unlikely to be very rivetting stuff.
...
> If you try to build on what macro-based thinkers know to explain how
> an S based system differs (and offers more) you can find that in just
> explaining those differences you unwittingly supply the very
> information they need to feed their desperation and you end up
> creating that barrier for them that they are so anxious to erect!
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, 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.
> 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.
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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