check_patterns: Check if column names start with patterns

View source: R/RcppExports.R

check_patternsR Documentation

Check if column names start with patterns

Description

This helper function takes two character vectors mainstrs and patterns, returning a boolean indicating whether each element of patterns is a string pattern in which at least one element of mainstrs starts with. In other words, for each element of patterns, does any element of mainstrs start with this particular pattern? If so, return TRUE. This helper can be used to efficiently verify the argument patterns in split_df(), especially when there is a large number of patterns.

Usage

check_patterns(mainstrs, patterns)

Arguments

mainstrs

A character vector of strings that are checked against each element in patterns.

patterns

A character vector of pattern strings.

Value

A logical vector with the same length as patterns, indicating whether each pattern is one that at least one string in mainstrs starts with.

Examples


# Vector of patterns
patterns <- c("prefix_1", "predix_2", ...)

# Checking if these patterns are valid for 'df'
check_patterns(mainstrs = names(df), patterns) |> all()

# Find all invalid patterns
valid_index <- check_patterns(mainstrs = names(df), patterns)
patterns[!valid_index]


YangWu1227/citizenr documentation built on June 18, 2022, 12:17 p.m.