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 8862903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:50:32+00:00 2026-06-14T15:50:32+00:00

Many functions’ outputs come in the list structure – for example lm(). As a

  • 0

Many functions’ outputs come in the list structure – for example lm(). As a result, you can retrieve the separate section of the output using “$” or indexation with square brackets. My question is how I can create an output in list form, without overtly showing that it is a list. As you know, when a list is printed on the screen, it typically has the sub-list name or index indicated, such as below:

L1 = list(a=1:3, b=letters[1:3])
L1

$a
[1] 1 2 3

$b
[1] "a" "b" "c"

However, lm() output never shows the different sub-lists using “$” and sub-list names – although you can extract these sub-lists using “$” and sub-list names.

A second question pertains to the fact that some functions’ outputs include much more than what is actually printed on the screen (e.g., lm(), again). If we use str() for the fitted model, we will see a whole bunch of content within the fitted model most of which is not printed. How is this achieved? Does the function print something and output something else (using invisible()) separately like below?

foo = function(x){
   result = list(data=x, test.result=t.test(x))
   print(result[[2]])
   invisible(result)
}
foo(1:10)$data

Thanks!

  • 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-06-14T15:50:33+00:00Added an answer on June 14, 2026 at 3:50 pm

    Read up on S3 classes. Specifically, when you type just an object name at the prompt, R calls print, which has methods for different classes.

    Take a look at print.lm to see how this works.

    > test <- list()
    > class(test) <- "myclass"
    > print.myclass <- function(x) cat("hi")
    > test
    hi
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've tried many functions already, but I simply can't figure this out. The right
Many functions in my code use this structure: options = {param1: yes, param2 :
Many functions can be reduced to point free form - but is this true
Many functions of a library I use return generator s instead of list s
I have looked at as many functions as I can and I still can't
I can see that the TextUtils class has many functions that are identical in
Many functions in c take pointer to constant strings/chars as parameters eg void foo(const
I have a js variable with many functions, and I want to create in
I do not use that many functions but when I do I tend to
I have a c++ program which has many many functions and I have different

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.