[Rd] Avoiding name clashes: opinion on best practice naming conventions

Dominick Samperi djsamperi at gmail.com
Wed Feb 16 18:43:47 CET 2011


On Wed, Feb 16, 2011 at 4:29 AM, Janko Thyson
<janko.thyson.rstuff at googlemail.com> wrote:
> Dear List,
>
> I'm trying to figure out some best practice way with respect to the naming
> conventions when building own packages.
>
> I'd like to minimize the risk of choosing function names that might
> interfere with those of other packages (both available ones and those yet to
> come).
>
> I came up with following alternatives
> 1. Prefixing the actual names (e.g. myPkgfoo() instead of foo()): pretty
> verbose
> 2. Emulating a package namespace while developing and explicitly using
> myPkg::foo() in all scripts: IMHO the best way, but apparently not possible
> as I learned.

Since the resolution of myPkg::foo() occurs at runtime (via a function
call) instead
of at compile time (as it would in C++), this practice can introduce a
significant
performance hit. This can be avoided by doing something like:
mylocalfunc <- myPkg::foo
[tight loop that uses mylocalfunc repeatedly]

Here mylocalfunc would not be exported, of course.

Dominick

> 3. Carefully choosing which functions to export. Yet, I'm not sure I
> completely understand the implications of exported functions. Does this
> imply that not exported functions cannot interfere with functions in other
> namespaces?
>
> I'd be great to hear some recommendations on this one!
>
> Thanks a lot,
> Janko
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



More information about the R-devel mailing list