var_names: Get variable names

Description Usage Arguments Details Value Author(s) Examples

View source: R/utils.R

Description

It is often flexible to input variables in plotting functions, and this generic function convert most common inputs (character, numeric or formula) to a character vector of variable names.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
var_names(vars, data)

## Default S3 method:
var_names(vars, data)

## S3 method for class 'character'
var_names(vars, data)

## S3 method for class 'numeric'
var_names(vars, data)

## S3 method for class 'formula'
var_names(vars, data)

Arguments

vars

a character vector of variable names, or a numeric vector of column indices, or a two-sided formula like ~ x1 + x2 + x3

data

the data containing the variables

Details

Numeric indices are converted to character names according to the positions of variables in the data; all.vars is used to extract all variable names in a formula, and the special formula ~ . is treated differently: it means all variables in the data except thoese names starting with a dot (e.g. .color).

Value

A character vector

Author(s)

Yihui Xie <http://yihui.name>

Examples

1
2
3
var_names(~., mtcars)
var_names(~disp + hp, mtcars)
var_names(1:3, mtcars)

ggobi/cranvas documentation built on May 17, 2019, 3:10 a.m.