[R] a question about scoping functions

Rajarshi Guha rxg218 at psu.edu
Sat Mar 27 03:28:08 CET 2004


Hi,
 I've written some helper functions which are used by another function
(called func()). When func() is sourced I dont want the helper function
to be seen in the global namespace (as shown by ls()).

Currently what I have done is:

func <- function() {
  helper1 <- function() {
    ...
  }
  helper2 <- function() {
    ...
  }
  # some code
}

Is there anyway to take the functions helper1 and helper2 outside func
(but in the same file) yet keep them from showing up in the global
namespace when the source file for func() is loaded?

A related question is: say I move helper1 and helper2 to a file called
helper.R

When I want to use the helper functions inside func() I can do
source('helper.R') - but that would place them in the global namespace.
Is it possible to source some file within a func() such that the sourced
functions will be local to func()?

Thanks,
-------------------------------------------------------------------
Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net>
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
-------------------------------------------------------------------
Did you hear that two rabbits escaped from the zoo and so far they have
only recaptured 116 of them?




More information about the R-help mailing list