[R] control enviromnet
facS93@hampshire.edu
facS93 at hampshire.edu
Thu Oct 7 03:52:13 CEST 2004
thanks Roger,
this doesn't do exactly what I want, which I didn't explain clearly enough in
the original post. I want to have a check mechanism to find whether there are
variables in the function that are not "locally" defined, in which case I
wouldn't know in advance what they are - well, I probably should because I am
writing the function. It's just that when the function gets kind of large, and
I am testing it as I am building it, it's easy to lose track of all these
variables.
thanks,
Fang
Quoting "Roger D. Peng" <rpeng at jhsph.edu>:
> I think you want something like
>
> exists("x", where = environment(), inherits = FALSE)
>
> -roger
>
> facS93 at hampshire.edu wrote:
> > Hi all:
> >
> > I would like to implement an option in my function so that it warns me of
> any
> > variables that are not defined in the current environment - if it needs to
>
> > look up variables in the parent frame, it tells me so.
> >
> > The following is an example and it does what I want, and I'd rather have
> the
> > environment control option inside this function instead of outside. Any
> help
> > would be greatly appreciated.
> >
> > x = 1
> > test = function(y) {
> > ans = y + x;
> > return(ans);
> > }
> > environment(test)=NULL
> > test(y = 1)
> >
> > Thanks much!
> >
> > Fang
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
> >
>
More information about the R-help
mailing list