Skip to contents

To define a dimension in a dimensional_model object, we have to define its name and the set of attributes that make it up.


define_dimension(st, name = NULL, attributes = NULL)

# S3 method for dimensional_model
define_dimension(st, name = NULL, attributes = NULL)



A dimensional_model object.


A string, name of the dimension.


A vector of attribute names.


A dimensional_model object.


To get a star schema (a star_schema object) we need a flat table (implemented through a tibble) and a dimensional_model object. The definition of dimensions in the dimensional_model object is made from the flat table column names. Using the dput function we can list the column names of the flat table so that we do not have to type their names.

See also

Other star definition functions: define_fact(), dimensional_model()


# dput(colnames(mrs_age))
# c(
#   "Reception Year",
#   "Reception Week",
#   "Reception Date",
#   "Data Availability Year",
#   "Data Availability Week",
#   "Data Availability Date",
#   "Year",
#   "WEEK",
#   "Week Ending Date",
#   "REGION",
#   "State",
#   "City",
#   "Age Range",
#   "Deaths"
# )

dm <- dimensional_model() |>
  define_dimension(name = "When",
                   attributes = c("Week Ending Date",
                                  "Year")) |>
  define_dimension(name = "When Available",
                   attributes = c("Data Availability Date",
                                  "Data Availability Week",
                                  "Data Availability Year")) |>
  define_dimension(name = "Where",
                   attributes = c("REGION",
                                  "City")) |>
  define_dimension(name = "Who",
                   attributes = c("Age Range"))