Download data/R/utils_stringr.R from introvoyz045/CoRC: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/datasets/introvoyz045/CoRC/resolve/main/data/R/utils_stringr.R
- Command line
-
hf download hf://datasets/introvoyz045/CoRC/data/R/utils_stringr.R
-
curl -L -o utils_stringr.R https://huggingface.co/datasets/introvoyz045/CoRC/resolve/main/data/R/utils_stringr.R
1.05 kB
| #' String matching engines from stringr | |
| #' | |
| #' @details CoRC makes use of the string matching engines from the \pkg{stringr} package. | |
| #' | |
| #' The functions are described at \link[stringr]{modifiers}. | |
| #' By default, matching is done with \code{coll}. | |
| #' | |
| #' @name regex | |
| NULL | |
| #' @export | |
| #' @rdname regex | |
| stringr::fixed | |
| #' @export | |
| #' @rdname regex | |
| stringr::coll | |
| #' @export | |
| #' @rdname regex | |
| stringr::regex | |
| # checks if a stringr engine is applied | |
| # this function depends on the version of the stringr package. If an old version is detected, this is overwritten in .onLoad | |
| has_engine <- function(x) inherits(x, c("stringr_fixed", "stringr_coll", "stringr_regex")) | |
| # apply an engine for a character vector | |
| # do nothing if engine is already applied | |
| apply_engine <- function(x, engine = coll) { | |
| if (!has_engine(x)) | |
| x <- engine(x) | |
| x | |
| } | |
| # Subsetting vectors with engine attribute (x[1]) usually clears all attributes | |
| # This method prevents that | |
| subset_engine <- function(x, i) { | |
| attrs <- attributes(x) | |
| x <- x[i] | |
| attributes(x) <- attrs | |
| x | |
| } | |