Skip to content

Instantly share code, notes, and snippets.

@robertzk
Created December 6, 2013 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertzk/7833479 to your computer and use it in GitHub Desktop.
Save robertzk/7833479 to your computer and use it in GitHub Desktop.
R exercise: Write your own version of exists(inherits = FALSE) (Hint: use ls()). Write a recursive version that behaves like inherits = TRUE. http://adv-r.had.co.nz/Environments.html
exists <- function(name, env = parent.frame(), inherits = TRUE) {
if (identical(env, emptyenv())) return(FALSE)
if (name %in% ls(envir = env)) TRUE
else if (inherits) exists(name, parent.env(env))
else FALSE
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment