[R] Hiding a function from ls()

Martin Maechler maechler at stat.math.ethz.ch
Thu Dec 22 10:44:00 CET 2005


>>>>> "Erich" == Erich Neuwirth <erich.neuwirth at univie.ac.at>
>>>>>     on Thu, 22 Dec 2005 10:06:38 +0100 writes:

    Erich> I need to define a small helper function
    Erich> which should not be listed by ls().

    Erich> What is the best and cleanest way of achieving this?

"it depends":

1) if it's part of a package, the best and cleanest is 
   - have the package use a namespace
   - do nothing special at, so your helper function is not
      exported from the namespace, and hence not much visible at all.
 
   The encouraged use of much more such helper function
   (i.e. "modular programming") is one prominent reason
   for using name spaces.

2) If it's just part of a small script  {anything else should be
   in a package anyway :-)},

   just start the function name with a "." (dot).
   Then, ls() only would list it when used with the additional
   argument setting  ls(...,  all.names = TRUE)


Martin Maechler, ETH Zurich




More information about the R-help mailing list