Skip to contents

To define the fact to be consulted, its name is indicated, optionally, a vector of names of selected measures, another of aggregation functions and another of new names for measures are also indicated.

Usage

select_fact(sq, name, measures, agg_functions, new, nrow_agg)

# S3 method for star_query
select_fact(
  sq,
  name = NULL,
  measures = NULL,
  agg_functions = NULL,
  new = NULL,
  nrow_agg = NULL
)

Arguments

sq

A star_query object.

name

A string, name of the fact.

measures

A vector of measure names.

agg_functions

A vector of aggregation function names, each one for its corresponding measure. They can be SUM, MAX or MIN.

new

A vector of measure new names.

nrow_agg

A string, name of a new measure that represents the COUNT of rows aggregated for each resulting row.

Value

A star_query object.

Details

If there is only one fact table, it is the one that is considered if no name is indicated.

If no aggregation function is given, those defined for the measures are considered.

If no new names are given, the original names will be considered. If the aggregation function is different from the one defined by default, it will be included as a prefix to the name.

Examples


sq <- mrs_db |>
  star_query()

sq_1 <- sq |>
  select_fact(
    name = "mrs_age",
    measures = "all_deaths",
    agg_functions = "MAX"
  )

sq_2 <- sq |>
  select_fact(name = "mrs_age",
              measures = "all_deaths")

sq_3 <- sq |>
  select_fact(name = "mrs_age")