Learn R Programming

lsr (version 1.0.0)

importList: Import a list into the workspace

Description

Copies each element of a list into a separate variable in the workspace, using the list element names as variable names.

Usage

importList(x, ask = TRUE)

Value

Called primarily for its side effect of creating variables in the workspace. Invisibly returns 1 if variables were created, 0

if the user declined.

Arguments

x

A list or data frame whose elements are to be imported as individual variables.

ask

Set to TRUE (the default) to display the names of the variables that will be created and ask for confirmation before proceeding. Set to FALSE to import silently.

Details

Creates one variable per list element in the calling environment (usually the global workspace). All elements of x must be named; passing an unnamed or partially-named list is an error. Element names that are not valid R variable names are automatically converted using make.names. An empty list produces a message and returns invisibly without creating any variables.

See Also

Examples

Run this code
values <- c(1, 2, 3, 4, 5)
group <- c("group A", "group A", "group B", "group B", "group B")

# split() returns a named list: one element per group
grp_list <- split(values, group)

# import silently (no confirmation prompt)
importList(grp_list, ask = FALSE)

if (FALSE) {
  # interactive: shows variable names and asks for confirmation
  importList(grp_list)
}

Run the code above in your browser using DataLab