Skip to contents

stm_unpack() assigns elements of a list, named vector, or data frame to the specified environment, creating variables for each element.

Usage

stm_unpack(dat, output = FALSE, envir = .GlobalEnv)

Arguments

dat

A list, named vector, or data frame to unpack into variables.

output

Logical. If TRUE, displays the unpacked variable names and their values. Default is FALSE.

envir

The environment in which to unpack variables. Default is .GlobalEnv.

Value

Invisibly returns NULL. The function creates variables in the specified environment.

Details

This function allows you to unpack elements of a supported data structure (list, named vector, or data frame) and assign them as variables in the specified environment. If data is not of a supported type, an error is raised.

Examples

lst <- list(a = 10, b = 20, c = 30)
print(lst)
#> $a
#> [1] 10
#> 
#> $b
#> [1] 20
#> 
#> $c
#> [1] 30
#> 
stm_unpack(lst)
a
#> [1] 10
b
#> [1] 20
c
#> [1] 30

v <- c(x = 1, y = 2, z = 3)
print(v)
#> x y z 
#> 1 2 3 
stm_unpack(v)
a
#> [1] 10
b
#> [1] 20
c
#> [1] 30