Skip to contents

This function removes elements from an indexable object (e.g., a named vector or list) where the names match a specified regular expression.

Usage

rmByName(x, pattern, silent = FALSE)

Arguments

x

An indexable object (e.g., a named vector, list, or data frame).

pattern

A character containing a regular expression(s) to match the names of elements to be removed.

silent

A logical indicating whether to silence a warning if no names are detected.

Value

The input object with elements removed based on the name regex.

Examples

myList <- list(a = 1, b_test = 2, c = 3, d_test = 4)
rmByName(myList, "_test")
#> $a
#> [1] 1
#> 
#> $c
#> [1] 3
#>