Skip to content

Make packages loaded by load_all() children of global environment #125

Description

@wch

Objects loaded via load_all() behave somewhat differently from loading those loaded with library().

With load_all(), the package environment is not a child of the global environment. But with library(), it is a child of the global environment.

This code will illustrate:

# This prints all parent environments, until it hits top (emptyenv)
printenvs <- function(e = parent.frame(), n = 100) {
  cat(str(e, give.attr=F))
  i <- 1
  while(i < n) {
    if (identical(e, emptyenv()))
      break

    e <- parent.env(e)
    cat(str(e, give.attr=F))
    i <- i+1
  }
  cat("\n")
  return(e)
}


library(ggplot2)
debugonce(qplot)
qplot()
printenvs()
# <environment: R_GlobalEnv> is a parent


# === Might need to restart R to do this ===
library(devtools)
load_all('.')
debugonce(qplot)
qplot()
printenvs()
# <environment: R_GlobalEnv> is not a parent

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions