I'm new to R and was trying to write a function to search for an object in all the environments.
The following piece of lines work fine but when I include them inside a 'while' loop, they don't work. I think I'm missing something here. Any help?
    name<-10
    env=parent.frame()
    !identical(env,emptyenv())
    exists('name',envir=env,inherits = FALSE)
    env<-parent.env(env)
    env
Codes in while loop
    MyWhere<-function(name,env=parent.frame){
       while(!identical(env,emptyenv())){
    if (exists(name,envir=env,inherits = FALSE)) {
        env
       }
    else {
        env<-parent.env(env)
        }
      }
    }
    MyWhere('a')
Error message - Error in exists(name, envir = env, inherits = FALSE) : invalid 'envir' argument
 
     
    