[R] control enviromnet

Roger D. Peng rpeng at jhsph.edu
Thu Oct 7 03:34:09 CEST 2004


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