[R-SIG-Mac]Prettying up functions

Thomas Lumley tlumley@u.washington.edu
Mon, 14 Jan 2002 08:24:22 -0800 (PST)


On Sun, 13 Jan 2002, Peter Macdonald wrote:

> I like the way Splus "pretties up" functions with consistent spacing,
> indents, etc. automatically when you exit fix() but R doesn't seem to do
> this so I wrote
>
> > fixup
> function (myfun)
> {
>     dput(myfun, "fixup.tmp")
>     dget("fixup.tmp")
> }
>
> Is there some other way to do this?
>

Yes.
    attr(myfun,"source")<-NULL
or you  can turn off non-prettying for all new functions by setting
   options(keep.source=FALSE)

R, by default, keeps a copy of the source code for a newly created
function (though not for a function in the base package). The primary
reason is to ensure that comments stay exactly where they are put, which
is quite hard to arrange when parsing and deparsing.

BTW, this is described in the 'Writing R Extensions' manual, where we
recommend prettying up the code of packages, followed by hand-editing.


	-thomas