list_edit: Edit a list

View source: R/list_edit.R

list_editR Documentation

Edit a list

Description

Edit the elements of a list by name

Usage

list_edit(.l, ..., .add = TRUE)

Arguments

.l

List to edit

...

Named elements to add or delete

.add

Should named elements not existing in the original list be added?

Details

list_edit is similar to purrr::list_modify in purrr, but unlike list_modify, does not operate recursively on a list. It only edits elements at the top level of hierarchy. Elements can be removed by setting them equal to NULL.

Examples

list_edit(list(x = 1, y = 2), x = 10, z = 20)
list_edit(list(x = 1, y = 2), x = NULL, y = 5)
list_edit(list(x = 1, y = 2), !!!list(x = NULL, z = 100))
list_edit(list(x = 1, y = 2), x = 10, z = 20, .add = FALSE)

mvanhala/rutils documentation built on Feb. 13, 2023, 9:08 a.m.