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

  • Home
  • SEARCH
  • 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 6569435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:37:35+00:00 2026-05-25T14:37:35+00:00

It would be helpful if someone can illustrate this with a simple example? Also,

  • 0

It would be helpful if someone can illustrate this with a simple example?

Also, where would it be useful to use parent.frame() instead of parent.env() and vice versa.

  • 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-25T14:37:36+00:00Added an answer on May 25, 2026 at 2:37 pm

    parent.env is the environment in which a closure (e.g., function) is defined. parent.frame is the environment from which the closure was invoked.

    f = function() 
         c(f=environment(), defined_in=parent.env(environment()),  
           called_from=parent.frame())
    g = function() 
         c(g=environment(), f())
    

    and then

    > g()
    $g
    <environment: 0x14060e8>
    
    $f
    <environment: 0x1405f28>
    
    $defined_in
    <environment: R_GlobalEnv>
    
    $called_from
    <environment: 0x14060e8>
    

    I’m not sure when a mere mortal would ever really want to use them, but the concepts are useful in understanding lexical scope here

    > f = function() x
    > g = function() { x = 2; f() }
    > h = function() { x = 3; function() x }
    > x = 1
    > f()
    [1] 1
    > g()
    [1] 1
    > h()()
    [1] 3
    

    or in the enigmatic ‘bank account’ example in the Introduction to R. The first paragraph of the Details section of ?parent.frame might clarify things.

    Environments are pervasive in R, e.g., the search() path is (approximately) environments chained together in a sibling -> parent relationship. One sometimes sees env = new.env(parent=emptyenv()) to circumvent symbol look-up — normally env[["x"]] would look first in env, and then in env‘s parent if not found. Likewise, <<- looks for assignment starting in the parent.env. The relatively new reference class implementation in R relies on these ideas to define an instance-specific environment in which symbols (instance fields and methods) can be found.

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

Sidebar

Related Questions

I understand I can use pointers for functions. Can someone explain why one would
I thought the following selector would only match example b . Can someone explain
If yes then presentational elements would be helpful in this condition so should we
Can someone explain to me this code new Object[]{PLease,Help}; Ive never seen code like
I hope that someone can help me with this problem that I've been having
I am having a hard time understanding this and hopefully someone can correct me
The exact exception message would be helpful, too. Thanks.
[I'm not asking about the architecture of SO, but it would be helpful to
On long Visual C++ builds, it would be really helpful to hear some sort
Would the following SQL remove also the index - or does it have to

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.