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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:46:46+00:00 2026-06-15T03:46:46+00:00

If I have two nested environments using the same variable name, how would I

  • 0

If I have two nested environments using the same variable name, how would I grab the value of the outer environment?

I am having difficulty figuring out the correct way to implement this. I have tried a few variations of parent.frame(x) and sys.frame(x) inside eval. Any suggestions would be appreciated.


EXAMPLE:

outerFunc <- function() { 
  obj <- "Outer Object"
  innerFunc()
}

innerFunc <- function() {
  # A local variable with same name is created
  obj <- "Inner Object"

  # would like to grab the value of obj from the outer environment
  obj.callingFunc <- eval(obj, envir=sys.frame(-1))

  cat(obj.callingFunc)  # gives "Inner Object" instead of "Outer Object"
} 

> outerFunc()
Inner Object

The obvious solutions (Pass obj explicitly. Use a different variable name, etc) are not available to me in this specific case.


EDIT

examining @GregSnow’s and @Dwin’s answers below

  # THESE WORK
  eval(quote(obj), envir=parent.frame()) # equivalent to evalq(obj, envir=parent.frame())
  get("obj", envir=parent.frame())

  # THESE DO *NOT* WORK
  eval("obj", envir=parent.frame()) 
  get(quote(obj), envir=parent.frame())

Any thoughts as to the effects of quoting in get() vs eval()?



  • 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-15T03:46:47+00:00Added an answer on June 15, 2026 at 3:46 am
    outerFunc <- function() { 
      obj <- "Outer Object"
      innerFunc()
    }
    
    innerFunc <- function() {
      # A local variable with same name is created
      obj <- "Inner Object"
    
      # would like to grab the value of obj from the outer environment
      cat( get('obj', envir=parent.frame()) )
    
       } 
    
     outerFunc()
    #Outer Object
    

    Could have also used: eval(quote(obj), envir=sys.frame(-1)). It becomes clear that the meaning of quote(expr) is different than than of “expr”. The get function is “expecting” (or perhaps more accurately is designed) to receive character values, whereas eval is expecting calls and expressions, i.e “language” objects. There is sort of a semi-permeable membrane between data and language in R and get is one of the membrane channels through which you can pass character valued objects to language domain.

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

Sidebar

Related Questions

I have two nested DropDownLists (the value selected in the 1st ddl will limit
how to implement inner outer classes in c# i have two nested classes like
I have two nested repeaters in C#. The outer has some grouping information and
I have nested grids in my views and would like to use same CSS
I have two nested packages that I am calling via fast_cgi. From the first
I have two nested loop in XSL like this, at this moment I use
I have two masterpages. A main.Master and a search.Master. The search.Master is a nested
I have two tables: Campaigns, Campaign_statistics. I need to output campaigns list with nested
I have a navigation bar that has two dropdowns (as nested ul's). I'm trying
I have two nested arrays and need to find the difference between the reference

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.