Assume you are working with a large working environment and you aren't great about keeping up with your environment variables, or you have some process that generates a lot objects automatically. Is there a way to scan your ls()
to identify all objects that have a given class? Consider the following simple example:
#Random objects in my environment
x <- rnorm(100)
y <- rnorm(100)
z <- rnorm(100)
#I estimate some linear models for fun.
lm1 <- lm(y ~ x)
lm2 <- lm(y ~ z)
lm3 <- lm(y ~ x + z)
#Is there a programmatic way to identify all objects in my environment
#that are of the "lm" class? Or really, any arbitrary class?
outList <- list(lm1, lm2, lm3)
#I want to look at a bunch of plots for all the lm objects in my environment.
lapply(outList, plot)
See Question&Answers more detail:os