list.to.env: Create variables from a list

View source: R/NCmisc.R

list.to.envR Documentation

Create variables from a list

Description

Places named objects in a list into the working environment as individual variables. Can be particularly helpful when you want to call a function that produces a list of multiple return variables; this gives a way to access them all at once in the environment from which the function was called.

Usage

list.to.env(list)

Arguments

list

list, with named objects, each element will become a named variable in the current environment

Value

New variables will be added to the current environment. Use with care as any already existing with the same name will be overwritten.

See Also

base::list2env

Examples

list.to.env(list(myChar="a string", myNum=1234, myList=list("list within a list",c(1,2,3))))
print(myChar)
print(myNum)
print(myList)
two.arg.return <- function(X) { return(list(Y=X+1,Z=X*10)) } 
result <- two.arg.return(11) # function returns list with 2 variables
list.to.env(result)
print(Y); print(Z)

NCmisc documentation built on Oct. 17, 2022, 5:09 p.m.