[Rd] A where() functions that does what exists() does but return the environment when object lives?
Hadley Wickham
h.wickham at gmail.com
Tue Oct 13 23:44:08 CEST 2015
On Tue, Oct 13, 2015 at 4:43 PM, Hadley Wickham <h.wickham at gmail.com> wrote:
> Seems easy enough to write yourself:
>
> where <- function(x, env = parent.frame()) {
> if (identical(env, emptyenv()))
> return(NULL)
> if (exists(x, envir = env, inherits = FALSE))
> return(env)
> where(x, parent.env(env))
> }
>
> sample2 <- base::sample
> where("sample2")
> #> <environment: 0x1154d3c28>
And that returns a random environment because I ran it with
reprex::reprex(). In interactive use it will return <environment:
R_GlobalEnv>
Hadley
--
http://had.co.nz/
More information about the R-devel
mailing list