cfilter: Filter a List by Class

View source: R/general_utils.R

cfilterR Documentation

Filter a List by Class

Description

Filters a list, keeping or excluding elements based on their class.

Usage

cfilter(x, class, not = FALSE)

Arguments

x

A list of R objects.

class

A character string specifying the class to filter by.

not

Logical; if 'TRUE', elements *not* inheriting from 'class' are kept. Default is 'FALSE'.

Value

A list containing the elements of 'x' that (do not) inherit from the specified class.

Examples

lst <- list(1L, "text", 3.14, list(a = 1))
cfilter(lst, "numeric")  # returns elements that are numeric
cfilter(lst, "character")  # returns character elements
cfilter(lst, "numeric", not = TRUE)  # returns elements that are NOT numeric


filippogambarota/filor documentation built on July 3, 2025, 8:39 p.m.