get_sub_name: Get a Substituted Name as Character for Subsetting

Description Usage Arguments Value Examples

View source: R/utils_subsets.R

Description

This generic function is primarily useful for functions that accept column names for subsetting data. The goal is to provide methods for users to supply either an unquoted column name or a quoted one (character string). It makes use of the fact that calling substitute() on a character string has a class "character", and class "name" otherwise.

Usage

1

Arguments

x

The substituted column name.

Value

The character vector for use with subsetting data.

Examples

1
2
3
4
5
6
7
get_col <- function(data, column) {
  name <- substitute(column)
  data[, get_sub_name(name)]
}

get_col(mtcars, hp)
get_col(mtcars, "hp")

jdtrat/jdtools documentation built on Dec. 20, 2021, 10:05 p.m.