Skip to contents

Rename attributes in a flat table or a dimension in a star database.

Usage

# S3 method for flat_table
set_attribute_names(db, name = NULL, old = NULL, new)

set_attribute_names(db, name, old, new)

# S3 method for star_database
set_attribute_names(db, name, old = NULL, new)

Arguments

db

A flat_table or star_database object.

name

A string, dimension name.

old

A vector of names.

new

A vector of names.

Value

A flat_table or star_database object.

Details

To rename the attributes there are three possibilities: 1) give only one vector with the new names for all the attributes; 2) a vector of old names and another of new names that must correspond; 3) a vector of new names whose names are the old names they replace.

Examples


db <- star_database(mrs_cause_schema, ft_num) |>
  set_attribute_names(
    name = "where",
    new = c(
      "Region",
      "State",
      "City"
    )
  )

db <- star_database(mrs_cause_schema, ft_num) |>
  set_attribute_names(name = "where",
                      old = "REGION",
                      new = "Region")

new <- "Region"
names(new) <- "REGION"
db <- star_database(mrs_cause_schema, ft_num) |>
  set_attribute_names(name = "where",
                      new = new)

ft <- flat_table('iris', iris) |>
  set_attribute_names(
    old = 'Species',
    new = 'species')

new <- "species"
names(new) <- "Species"
ft <- flat_table('iris', iris) |>
  set_attribute_names(
    new = new)