Skip to contents

Returns column.name if it is not already present in df. If the name is already used, a numeric suffix is appended to create a unique column name.

Usage

check_column_name(df, column.name)

Arguments

df

A data frame.

column.name

A proposed column name.

Value

A character scalar containing an available column name.

Author

Xiaotao Shen xiaotao.shen@outlook.com

Examples

df <-
  data.frame(x = 1:2, y = 2:3, y.1 = 3:4)
df
#>   x y y.1
#> 1 1 2   3
#> 2 2 3   4

check_column_name(df = df, column.name = "y")
#> [1] "y.2"
check_column_name(df = df, column.name = "y.1")
#> [1] "y.1.2"