
Select names matching a pattern
select_grep(
DT,
patterns,
.and = NULL,
.but.not = NULL,
ignore.case = FALSE,
perl = TRUE,
fixed = FALSE,
useBytes = FALSE,
invert = FALSE,
.warn.fixed.mismatch = TRUE
)
A data.frame
.
Regular expressions to be matched against the names of DT
. If length(patterns) > 1
the patterns are concatenated using alternation.
Character or integer positions of names to select, regardless of whether or not they are matched by patterns
.
Character or integer positions of names to drop, regardless of whether or not they are matched by patterns
or whether they are explicitly added by .and
.
Arguments passed to grep
. Note that perl = TRUE
by default (unlike grep
) unless fixed = TRUE
(and perl
is missing).
(logical, default: TRUE
) If TRUE
, the default, selecting fixed = TRUE
with perl = TRUE
or ignore.case = TRUE
results in perl
and ignore.case
being reset to FALSE
with a warning (as in grep
), even if it makes no difference to the columns eventually selected. If FALSE
unambiguous results are allowed; if ignore.case = TRUE
and fixed = TRUE
, the result is unambiguous if select_grep(DT, tolower(patterns), fixed = TRUE)
and select_grep(DT, toupper(patterns), fixed = TRUE)
are identical.
DT
with the selected names.
integer vector of positions
# NOT RUN {
library(data.table)
dt <- data.table(x1 = 1, x2 = 2, y = 0)
select_grep(dt, "x")
select_grep(dt, "x", .and = "y")
select_grep(dt, "x", .and = "y", .but.not = "x2")
# }
Run the code above in your browser using DataLab