Define a role playing dimension and its associated dimensions
Source:R/role_playing.R
role_playing_dimension.Rd
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.
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).
See also
Other star database definition functions:
get_dimension_names()
,
get_dimension_table()
,
get_fact_names()
,
get_role_playing_dimension_names()
,
get_table_names()
,
group_dimension_instances()
,
star_database()
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"))