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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:45:49+00:00 2026-06-01T09:45:49+00:00

I would like to ask if it is possible to copy/move all the objects

  • 0

I would like to ask if it is possible to copy/move all the objects of one environment to another, at once. For example:

f1 <- function() {
    print(v1)
    print(v2)
}

f2 <- function() {
    v1 <- 1
    v2 <- 2

    # environment(f1)$v1 <- v1         # It works
    # environment(f1)$v2 <- v2         # It works
    
    environment(f1) <- environment(f2) # It does not work
}

f2()
f1()
  • 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-01T09:45:50+00:00Added an answer on June 1, 2026 at 9:45 am

    There seem to be at least 3 different things you can do:

    1. Clone an environment (create an exact duplicate)
    2. Copy the content of one environment to another environment
    3. Share the same environment

    To clone:

    # Make the source env
    e1 <- new.env()
    e1$foo <- 1
    e1$.bar <- 2   # a hidden name
    ls(e1) # only shows "foo"
    
    # This will clone e1
    e2 <- as.environment(as.list(e1, all.names=TRUE))
    
    # Check it...
    identical(e1, e2) # FALSE
    e2$foo
    e2$.bar
    

    To copy the content, you can do what @gsk showed. But again, the all.names flag is useful:

    # e1 is source env, e2 is dest env
    for(n in ls(e1, all.names=TRUE)) assign(n, get(n, e1), e2)
    

    To share the environment is what @koshke did. This is probably often much more useful. The result is the same as if creating a local function:

    f2 <- function() {
      v1 <- 1 
      v2 <- 2
    
      # This local function has access to v1 and v2
      flocal <- function() {
        print(v1)
        print(v2)
      }
    
      return(flocal)
    } 
    
    f1 <- f2()
    f1() # prints 1 and 2 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: JavaScript: Why the anonymous function wrapper? I would like to ask you
I would like to ask if there is a possible way to select all
all. I would like to ask if it is possible to have multiple forms
I would like to ask if it is at all possible to let MySQL
I would like to ask you if is possible to add a shadow to
I would like to ask if is it possible to extract the exact variable
i would like to ask if it is possible to forbid pull-out of the
I'm a newbie in WPF and I would like to ask if it's possible
What I would like ask is best illustrated by an example, so bear with
I would like to ask you which automated build environment you consider better, based

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.