Translate column names or positions into DT column targets
Source:R/dataFilter_module_server.R
resolve_column_targets.RdMaps a set of columns onto the zero-based targets indices DataTables
expects inside a columnDefs entry. This is what dataFilterServer() uses
to honour its hide.columns argument, but it is useful for any hand-rolled
DT::datatable() where columns are referred to by name rather than by
position – hiding them, setting widths, disabling ordering, and so on.
Arguments
- data
A data frame, or a character vector of the column names in the order they are passed to
DT::datatable().- columns
NULL, a character vector of column names, or a numeric vector of one-based column positions to resolve.- rownames
Logical. Whether the table is drawn with a row-names column (the
rownamesargument ofDT::datatable()). WhenTRUE, row names occupy column 0 and every data column shifts one to the right, so the returned targets are shifted to match. Defaults toFALSE.
Details
Columns that do not exist are dropped with a warning rather than raising an error, so a table fed by a changing data frame keeps rendering when a column comes and goes.