Skip to content

recommended workflow for creating functions (was: Re: [Rd] Patch proposal for R style consistency (concerning deparse.c))

1 message · Liviu Andronic

#
(moving to r-help)

Dear all,
I think Paul is raising a useful question here: What is the
recommended workflow for creating a new function?

R prides itself for letting users to create and use home-brewed
functions: it's easy to maintain and re-use, doesn't clutter the
global environment with intermediary objects, has clear input and
output elements. All fine points, and I genuinely see the advantage in
using functions, but after several years of using R I still stumble at
step 1: building a function.

The thing is that I'm not a whizz programmer, so it takes me a lot of
time and mind gymnastics to imagine what the intermediary objects
within a function, when executed, would look like. Thus I need to see
and examine most intermediary objects while building the function. The
alternative is to create the input objects and use only the first
element while building the function, but this clutters the global
workspace and I need to worry about overwriting existing objects.
Another way would be to use browser() within the function, but this
seems clunky to me.

How do you deal with this? Is there a neat way to build a new function
in a "sandbox", where I can access all objects in the global workspace
but cannot overwrite them? Am I approaching this in the wrong way?

Opinions welcome. Regards,
Liviu
On Sun, May 5, 2013 at 7:37 PM, Paul Johnson <pauljohn32 at gmail.com> wrote: