as_env

0th

Percentile

Coerce to an environment.

This is a S3 generic. The default method coerces named vectors (including lists) to an environment. It first checks that x is a dictionary (see is_dictionary()). The method for unnamed strings returns the corresponding package environment (see pkg_env()).

Usage
as_env(x, parent = NULL)
"as_env"(x, parent = NULL)
"as_env"(x, parent = NULL)
"as_env"(x, parent = NULL)
"as_env"(x, parent = NULL)
Arguments
x
An object to coerce.
parent
A parent environment, empty_env() by default. Can be ignored with a warning for methods where it does not make sense to change the parent.
Details

If x is an environment and parent is not NULL, the environment is duplicated before being set a new parent. The return value is therefore a different environment than x.

Aliases
  • as_env
  • as_env.NULL
  • as_env.environment
  • as_env.character
  • as_env.default
Examples
# Coerce a named vector to an environment:
env <- as_env(mtcars)

# By default it gets the empty environment as parent:
identical(env_parent(env), empty_env())


# With strings it is a handy shortcut for pkg_env():
as_env("base")
as_env("rlang")

# With NULL it returns the empty environment:
as_env(NULL)
Documentation reproduced from package rlang, version 0.0.0.9000, License: GPL-3

Community examples

Looks like there are no examples yet.