dt.sub: In-place pattern matching and replacement in a data.table.

View source: R/dt_fun.R

dt.subR Documentation

In-place pattern matching and replacement in a data.table.

Description

In-place pattern matching and replacement in a data.table.

Usage

dt.sub(
  DT,
  pattern,
  replacement,
  ignore.case = FALSE,
  perl = FALSE,
  fixed = FALSE,
  useBytes = FALSE
)

Arguments

DT

A data.table.

pattern

A character string containing a regular expression (or character string for fixed = TRUE) to be matched in the given character vector. Coerced by as.character to a character string if possible. If a character vector of length 2 or more is supplied, the first element is used with a warning.

replacement

A character string replacement for matched pattern. Coerced to character if possible. For fixed = FALSE this can include backreferences "\1" to "\9" to parenthesized subexpressions of pattern. For perl = TRUE only, it can also contain "\U" or "\L" to convert the rest of the replacement to upper or lower case and "\E" to end case conversion. If a character vector of length 2 or more is supplied, the first element is used with a warning. If NA, all elements in the result corresponding to matches will be set to NA.

ignore.case

A logical. If FALSE, the pattern matching is case sensitive and if TRUE, case is ignored during matching.

perl

A logical. Should Perl-compatible regexps be used?

fixed

A logical. If TRUE, pattern is a string to be matched as is. Overrides all conflicting arguments.

useBytes

A logical. If TRUE the matching is done byte-by-byte rather than character-by-character.

Value

A data.table.

Author(s)

Yoann Pageaud.

Examples

dtbl<-data.table(col1 = rev(seq(16)), col2=rep(x = c("hello", "world"), 8))
dt.sub(DT = dtbl, pattern = "hello", replacement = "goodbye")

YoannPa/DTrsiv documentation built on Nov. 28, 2022, 5:44 p.m.