Skip to contents

The same dimension can play several roles in relation to the facts. We can define the main dimension and the dimensions that play different roles.

Usage

role_playing_dimension(db, rpd, roles, rpd_att_names, att_names)

# S3 method for star_database
role_playing_dimension(db, rpd, roles, rpd_att_names = FALSE, att_names = NULL)

Arguments

db

A star_database object.

rpd

A string, dimension name (role playing dimension).

roles

A vector of strings, dimension names (dimension roles).

rpd_att_names

A boolean, common attribute names taken from rpd dimension.

att_names

A vector of strings, common attribute names.

Value

A star_database object.

Details

As a result, all the dimensions will have the same instances and, if we deem it necessary, also the same name of their attributes (except the surrogate key).

Examples


s <- star_schema() |>
  define_facts(fact_schema(
    name = "mrs_cause",
    measures = c(
      "Pneumonia and Influenza Deaths",
      "All Deaths"
    )
  )) |>
  define_dimension(dimension_schema(
    name = "When",
    attributes = c(
      "Year",
      "WEEK",
      "Week Ending Date"
    )
  )) |>
  define_dimension(dimension_schema(
    name = "When Available",
    attributes = c(
      "Data Availability Year",
      "Data Availability Week",
      "Data Availability Date"
    )
  )) |>
  define_dimension(dimension_schema(
    name = "When Received",
    attributes = c(
      "Reception Year",
      "Reception Week",
      "Reception Date"
    )
  )) |>
  define_dimension(dimension_schema(
    name = "where",
    attributes = c(
      "REGION",
      "State",
      "City"
    )
  ))

db <- star_database(s, ft_cause_rpd) |>
  role_playing_dimension(
    rpd = "When",
    roles = c("When Available", "When Received"),
    rpd_att_names = TRUE
  )

db <- star_database(s, ft_cause_rpd) |>
  role_playing_dimension("When",
                         c("When Available", "When Received"),
                         att_names = c("Year", "Week", "Date"))