knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Note: This is not required reading. It will be helpful in understanding packages, scoping and masking, which any user will run into sooner or later but it is not crucial knowledge.




Environments

\newline

environment()

parent.env(environment())

\newline

# search returns a character vector, it will be easier to read as a matrix
cbind(search())
parent.env(as.environment('package:base'))
parent.env(emptyenv())

Most of the items on the search path are attached packages.

\newline

cbind(search())

library(lattice)
cbind(search())

package environments




Scoping

\newline

head(mtcars)

mtcars <- matrix(rep("mtcars", 100), 20, 5)
head(mtcars)

mtc <- get("mtcars", pos = "package:datasets")
head(mtc)
mtc <- datasets::mtcars
head(mtc)
head(barley)

head(lattice::barley)

\newline

Note that get can scope an object with a character string rather than a symbol


double arrow assignment

be careful when using double arrow assignment




This is by far not comprehensive, just some working knowledge. For more details check out R help pages for environment, search, attach, library. Read the Packages vignette before you do.




olobiolo/Rdlazer documentation built on Aug. 6, 2022, 11:37 a.m.