Unlimited learning, half price | 50% off

Last chance! 50% off unlimited learning

Sale ends in


NCmisc (version 1.2.0)

list.to.env: 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)

Value

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

Arguments

list

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

See Also

base::list2env

Examples

Run this code
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)

Run the code above in your browser using DataLab