Select columns from a data frame. Stop with message if columns do not exist
Usage
selectColumns(
x,
columns = NULL,
pattern = NULL,
drop = (length(columns) == 1),
do.stop = TRUE
)
Arguments
- x
data frame
- columns
vector of column names. If
columns
is of length 0 orNULL
(default) orNA
x
is returned unchanged.- pattern
regular expression matching the names of the columns to be selected. Will only be evaluated if no explicit column names are given in
columns
.- drop
if
TRUE
and if only one column is to be selected the result is a vector (one dimensional) containing the values of the selected column and not a data frame. One dimension has been dropped then. See thehelp("[.data.frame")
. The default isTRUE
iflength(columns) == 1
, elseFALSE
.- do.stop
this flag controls whether the function stops (
do.stop = TRUE
) or not (do.stop = FALSE
) if there are non-existing columns to be selected. Ifdo.stop = FALSE
only those columns are selected that actually exist