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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:56:45+00:00 2026-05-15T20:56:45+00:00

In the What is the most useful R trick? ( here ), I read

  • 0

In the “What is the most useful R trick?” (here), I read that using environments give “pass-by-reference capabilities”. Are there any limits and/or gotchas with this approach?

Also, in general what are the pros and cons of using created environments? This is something I’ve been confused about for quite some time, so any clarity or reference would be very helpful to me.

Thank you in advance.

  • 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-15T20:56:46+00:00Added an answer on May 15, 2026 at 8:56 pm

    While I agree with Harlan’s overall advice (i.e. don’t use something unless you understand it), I would add:

    Environments are a fundamental concept in R, and in my view, extremely useful (in other words: they’re worth understanding!). Environments are very important to understand issues related to scope. Some basic things that you should understand in this context:

    1. search(): will show you the workspace; environments are listed in order of priority. The main environment is .GlobalEnv, and can always be referenced as such.
    2. ls(): will show you what’s contained in an environment
    3. attach/detach: creates a new environment for an object
    4. get, assign, <<-, and <-: you should know the difference between these functions
    5. with: one method for working with an environment without attaching it.

    Another pointer: have a look at the proto package (used in ggplot), which uses environments to provide controlled inheritance.

    Lastly, I would point out that environments are very similar to lists: they can both store any kind of object within them (see this question). But depending on your use case (e.g. do you want to deal with inheritance and priority), a list can be easier to work with. And you can always attach a list as an environment.

    Edit: If you want to see an example of proto at work in ggplot, have a look that the structure of a ggplot object, which is essentially a list composed partially of environments:

    > p <- qplot(1:10, 1:10)
    > str(p)
    List of 8
     $ data       :'data.frame':    0 obs. of  0 variables
     $ layers     :List of 1
      ..$ :proto object 
     .. .. $ legend     : logi NA 
     .. .. $ inherit.aes: logi TRUE 
    ...
    > class(p$layers[[1]])
    [1] "proto"       "environment"
    > is.environment(p$layers[[1]])
    [1] TRUE
    

    Notice how it’s constructed using proto and is containing many environments as a result. You can also plot the relationships in these objects using graph.proto.

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

Sidebar

Related Questions

At top there is some most useful info about foo. Between horizontal lines there
HashTables/HashMaps are one of the most (if not the most) useful of data-structures in
Most of the MVC samples I have seen pass an instance of the view
I find that one of the most frustrating aspects to software development is finding
Most useful ActionScript packages / libraries for flash games
What is the most useful code generation tool in eclipse, velocity or jet templates
Is it beneficial to have WTP? Which features are most useful?
Most of my C/C++ development involves monolithic module files and absolutely no classes whatsoever,
Most of time we represent concepts which can never be less than 0. For
Most program languages have some kind of exception handling; some languages have return codes,

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.