duplicate_env: Create a duplicate of an environment

View source: R/utils.R

duplicate_envR Documentation

Create a duplicate of an environment

Description

Copy all items from the environment to a new environment. By default, the new environment will share the same parent environment.

Usage

duplicate_env(envir, parent = parent.env(envir))

Arguments

envir

environment to duplicate

parent

parent environment to set for the new environment. Defaults to the parent environment of envir.

Value

A duplicated copy of envir whose parent env is parent.

Examples

# Make a new environment with the object 'key'
envir <- new.env()
envir$key <- "value"
"key" %in% ls() # FALSE
"key" %in% ls(envir = envir) # TRUE

# Duplicate the envir and show it contains 'key'
new_envir <- duplicate_env(envir)
"key" %in% ls(envir = new_envir) # TRUE


learnr documentation built on Sept. 28, 2023, 9:06 a.m.