Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4001854
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:57:18+00:00 2026-05-20T07:57:18+00:00

Assume you are working with a large working environment and you aren’t great about

  • 0

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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:57:19+00:00Added an answer on May 20, 2026 at 7:57 am

    Use the class function:

    Models <- Filter( function(x) 'lm' %in% class( get(x) ), ls() )
    lapply( Models, function(x) plot( get(x) ) )
    

    (Modified slightly to handle situations where objects can have multiple classes, as pointed out by @Gabor in the comments).

    Update. For completeness, here is a refinement suggested by @Gabor’s comment below. Sometimes we may want to only get objects that are of class X but not class Y. Or perhaps some other combination. For this one could write a ClassFilter() function that contains all of the class filterling logic, such as:

    ClassFilter <- function(x) inherits(get(x), 'lm' ) & !inherits(get(x), 'glm' )
    

    Then you get the objects that you want:

    Objs <- Filter( ClassFilter, ls() )
    

    Now you can process the Objs whatever way you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume that you're working a x86 32-bits system. Your task is to implement the
I am working on a Java UI application that uses JDBC. I assume the
I'm a bit confused as to why this isn't working; I assume that because
Assume that we have two sets: A=(a_1,a_2,...,a_m) and B=(b_1,b_2,...,a_n) (Not necessarily of same size).
Working with a relatively large data set I have a situation where I need
I'm working on a project that involves parsing a large csv formatted file in
It is safe to assume that working with or passing around an immutable object
I'm working on a large PHP (Yii framework) web application where users have accounts
I'm working on a problem that requires caching paginated search results: Paginating very large
I have written a fairly large program in Fortran 90. It has been working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.