Title: | Definition of Date and Time Dimension Tables |
---|---|
Description: | In Multidimensional Systems the When dimension allows us to express when the analysed facts have occurred. The purpose of this package is to provide support for implementing this dimension in the form of date and time tables for Relational On-Line Analytical Processing star database systems. |
Authors: | Jose Samos [aut, cre] , Universidad de Granada [cph] |
Maintainer: | Jose Samos <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.0 |
Built: | 2024-11-05 06:30:46 UTC |
Source: | CRAN |
Precalculated date set
date_days
date_days
A vector.
Other time definition:
time_seconds
With this function we can define the characteristics of the dimension that do not depend on the levels it includes, such as the name, type, location or the day the week begins. It also allows us to define whether the table includes a surrogate key.
define_characteristics( td, name, surrogate_key, type, locale, week_starts_monday ) ## S3 method for class 'when' define_characteristics( td, name = NULL, surrogate_key = NULL, type = NULL, locale = NULL, week_starts_monday = NULL )
define_characteristics( td, name, surrogate_key, type, locale, week_starts_monday ) ## S3 method for class 'when' define_characteristics( td, name = NULL, surrogate_key = NULL, type = NULL, locale = NULL, week_starts_monday = NULL )
td |
A |
name |
A string, table name. |
surrogate_key |
A boolean, include a surrogate key in the dimension table. |
type |
A string, type of calendar (NULL, 'iso', 'epi' or 'time'). |
locale |
A locale, to use for day and month names. |
week_starts_monday |
A boolean. |
The week_starts_monday
parameter only affects the numbering of days, not weeks.
The week number associated with each date depends on the type of date dimension selected: standard ('date'), ISO 8601 ('iso') or epidemiological ('epi').
The standard week numbers blocks of 7 days beginning on January 1. The last week of the year can be less than 7 days long.
The ISO 8601 week numbers blocks of 7 days from Monday to Sunday. The first and last week of the year can contain days from the previous or next year.
The epidemiological week is like ISO 8601 only that it considers that the week begins on Sunday.
A when
object.
Other dimension definition:
define_instances()
,
get_attribute_definition_function()
,
get_day_part()
,
get_week_date_range()
,
select_date_levels()
,
select_day_level()
,
select_month_level()
,
select_quarter_level()
,
select_semester_level()
,
select_time_level()
,
select_week_level()
,
select_year_level()
,
set_attribute_definition_function()
,
set_day_part()
,
when()
td <- when() |> define_characteristics(name = 'time', type = 'time')
td <- when() |> define_characteristics(name = 'time', type = 'time')
Using this function we can define the instances from which the dimension will be generated according to the rest of its defined characteristics.
define_instances(td, start, end, values) ## S3 method for class 'when' define_instances(td, start = NULL, end = NULL, values = NULL)
define_instances(td, start, end, values) ## S3 method for class 'when' define_instances(td, start = NULL, end = NULL, values = NULL)
td |
A |
start |
A string, start of the period to be included in the dimension. |
end |
A string, end of the period to be included in the dimension. |
values |
A vector of string. |
We must indicate dates or date components in ISO 8601 format (yyyy-mm-dd). The times in hh:mm:ss format.
A when
object.
Other dimension definition:
define_characteristics()
,
get_attribute_definition_function()
,
get_day_part()
,
get_week_date_range()
,
select_date_levels()
,
select_day_level()
,
select_month_level()
,
select_quarter_level()
,
select_semester_level()
,
select_time_level()
,
select_week_level()
,
select_year_level()
,
set_attribute_definition_function()
,
set_day_part()
,
when()
td_1 <- when() |> define_instances(start = "2020", end = "2030") td_1 <- when() |> define_instances(start = "2020-01-01", end = "2030-01-01") td_2 <- when(type = 'time') |> define_instances(values = 1:5)
td_1 <- when() |> define_instances(start = "2020", end = "2030") td_1 <- when() |> define_instances(start = "2020-01-01", end = "2030-01-01") td_2 <- when(type = 'time') |> define_instances(values = 1:5)
Once all the characteristics of the dimension have been defined, we can generate its table according to them using this function.
generate_table(td) ## S3 method for class 'when' generate_table(td)
generate_table(td) ## S3 method for class 'when' generate_table(td)
td |
A |
A when
object.
Other obtaining results:
get_level_attribute_names()
,
get_level_names()
,
get_table_attribute_names()
,
set_table_attribute_names()
td <- when() |> generate_table()
td <- when() |> generate_table()
Each attribute is defined by a function that adds a column to a table based on the parameter that contains the date or time. This function returns the definition function for the attribute whose name is given.
get_attribute_definition_function(td, name) ## S3 method for class 'when' get_attribute_definition_function(td, name = NULL)
get_attribute_definition_function(td, name) ## S3 method for class 'when' get_attribute_definition_function(td, name = NULL)
td |
A |
name |
A string, attribute name. |
A function.
Other dimension definition:
define_characteristics()
,
define_instances()
,
get_day_part()
,
get_week_date_range()
,
select_date_levels()
,
select_day_level()
,
select_month_level()
,
select_quarter_level()
,
select_semester_level()
,
select_time_level()
,
select_week_level()
,
select_year_level()
,
set_attribute_definition_function()
,
set_day_part()
,
when()
f <- when() |> get_attribute_definition_function(name = "year")
f <- when() |> get_attribute_definition_function(name = "year")
Get day part.
get_day_part(td) ## S3 method for class 'when' get_day_part(td)
get_day_part(td) ## S3 method for class 'when' get_day_part(td)
td |
A |
A named vector.
Other dimension definition:
define_characteristics()
,
define_instances()
,
get_attribute_definition_function()
,
get_week_date_range()
,
select_date_levels()
,
select_day_level()
,
select_month_level()
,
select_quarter_level()
,
select_semester_level()
,
select_time_level()
,
select_week_level()
,
select_year_level()
,
set_attribute_definition_function()
,
set_day_part()
,
when()
dp <- when() |> get_day_part()
dp <- when() |> get_day_part()
Returns the names of the level attributes. We can obtain all the available ones or only the selected ones.
get_level_attribute_names(td, name, selected) ## S3 method for class 'when' get_level_attribute_names(td, name = NULL, selected = FALSE)
get_level_attribute_names(td, name, selected) ## S3 method for class 'when' get_level_attribute_names(td, name = NULL, selected = FALSE)
td |
A |
name |
A string. |
selected |
A boolean. |
A string vector.
Other obtaining results:
generate_table()
,
get_level_names()
,
get_table_attribute_names()
,
set_table_attribute_names()
names <- when() |> get_level_attribute_names()
names <- when() |> get_level_attribute_names()
Returns the names of the levels. We can obtain all the available ones or only the selected ones.
get_level_names(td, selected) ## S3 method for class 'when' get_level_names(td, selected = FALSE)
get_level_names(td, selected) ## S3 method for class 'when' get_level_names(td, selected = FALSE)
td |
A |
selected |
A boolean. |
A string vector.
Other obtaining results:
generate_table()
,
get_level_attribute_names()
,
get_table_attribute_names()
,
set_table_attribute_names()
names <- when() |> get_level_names()
names <- when() |> get_level_names()
Once all the configuration elements have been defined and the dimension table
has been generated, using this function we can obtain it in tibble
format.
get_table(td) ## S3 method for class 'when' get_table(td)
get_table(td) ## S3 method for class 'when' get_table(td)
td |
A |
A tibble
, the table.
Other getting results:
get_table_csv()
,
get_table_rdb()
,
get_table_xlsx()
table <- when() |> generate_table() |> get_table()
table <- when() |> generate_table() |> get_table()
Returns the names of the dimension table attributes as a string vector or in string form, so we can easily use it to rename them if deemed necessary.
get_table_attribute_names(td, as_string) ## S3 method for class 'when' get_table_attribute_names(td, as_string = TRUE)
get_table_attribute_names(td, as_string) ## S3 method for class 'when' get_table_attribute_names(td, as_string = TRUE)
td |
A |
as_string |
A boolean. |
If the table has not been generated yet, returns the attributes it will contain when it is generated.
A string.
Other obtaining results:
generate_table()
,
get_level_attribute_names()
,
get_level_names()
,
set_table_attribute_names()
names <- when() |> get_table_attribute_names()
names <- when() |> get_table_attribute_names()
Once all the configuration elements have been defined and the dimension table has been generated, using this function we can obtain it in csv format.
get_table_csv(td, dir, type) ## S3 method for class 'when' get_table_csv(td, dir = NULL, type = 1)
get_table_csv(td, dir, type) ## S3 method for class 'when' get_table_csv(td, dir = NULL, type = 1)
td |
A |
dir |
A string, name of a dir. |
type |
An integer, 1: uses "." for the decimal point and a comma for the separator; 2: uses a comma for the decimal point and a semicolon for the separator. |
If no dir name is given, stores the table in a temporary one.
A string, name of a file.
Other getting results:
get_table_rdb()
,
get_table_xlsx()
,
get_table()
file <- when() |> generate_table() |> get_table_csv()
file <- when() |> generate_table() |> get_table_csv()
Once all the configuration elements have been defined and the dimension table has been generated, using this function we can obtain it in table format in a Relational DBMS.
get_table_rdb(td, con, overwrite) ## S3 method for class 'when' get_table_rdb(td, con, overwrite = FALSE)
get_table_rdb(td, con, overwrite) ## S3 method for class 'when' get_table_rdb(td, con, overwrite = FALSE)
td |
A |
con |
A |
overwrite |
A boolean, allow overwriting tables in the database. |
Invisible NULL.
Other getting results:
get_table_csv()
,
get_table_xlsx()
,
get_table()
my_db <- DBI::dbConnect(RSQLite::SQLite()) when() |> generate_table() |> get_table_rdb(my_db) DBI::dbDisconnect(my_db)
my_db <- DBI::dbConnect(RSQLite::SQLite()) when() |> generate_table() |> get_table_rdb(my_db) DBI::dbDisconnect(my_db)
Once all the configuration elements have been defined and the dimension table has been generated, using this function we can obtain it in xlsx format.
get_table_xlsx(td, dir) ## S3 method for class 'when' get_table_xlsx(td, dir = NULL)
get_table_xlsx(td, dir) ## S3 method for class 'when' get_table_xlsx(td, dir = NULL)
td |
A |
dir |
A string, name of a dir. |
If no dir name is given, stores the table in a temporary one.
A string, name of a file.
Other getting results:
get_table_csv()
,
get_table_rdb()
,
get_table()
file <- when() |> generate_table() |> get_table_xlsx()
file <- when() |> generate_table() |> get_table_xlsx()
For weeks between the given dates, gets the date of the first and last day of each week.
get_week_date_range(start = NULL, end = NULL, type = NULL)
get_week_date_range(start = NULL, end = NULL, type = NULL)
start |
A string, start of the period to be included in the dimension. |
end |
A string, end of the period to be included in the dimension. |
type |
A string, type of calendar (NULL, 'iso', 'epi' or 'time'). |
A tibble
.
Other dimension definition:
define_characteristics()
,
define_instances()
,
get_attribute_definition_function()
,
get_day_part()
,
select_date_levels()
,
select_day_level()
,
select_month_level()
,
select_quarter_level()
,
select_semester_level()
,
select_time_level()
,
select_week_level()
,
select_year_level()
,
set_attribute_definition_function()
,
set_day_part()
,
when()
t <- get_week_date_range(start = "2024-01-01", end = "2029-12-31")
t <- get_week_date_range(start = "2024-01-01", end = "2029-12-31")
When the dimension is defined as date type, using this function we can select the levels to include in it: day, week, month, quarter, semester and year.
select_date_levels( td, include_all, exclude_all, day_level, week_level, month_level, quarter_level, semester_level, year_level ) ## S3 method for class 'when' select_date_levels( td, include_all = FALSE, exclude_all = FALSE, day_level = NULL, week_level = NULL, month_level = NULL, quarter_level = NULL, semester_level = NULL, year_level = NULL )
select_date_levels( td, include_all, exclude_all, day_level, week_level, month_level, quarter_level, semester_level, year_level ) ## S3 method for class 'when' select_date_levels( td, include_all = FALSE, exclude_all = FALSE, day_level = NULL, week_level = NULL, month_level = NULL, quarter_level = NULL, semester_level = NULL, year_level = NULL )
td |
A |
include_all |
A boolean, include all levels. |
exclude_all |
A boolean, exclude all levels. |
day_level |
A boolean, include day level. |
week_level |
A boolean, include week level. |
month_level |
A boolean, include month level. |
quarter_level |
A boolean, include quarter level. |
semester_level |
A boolean, include semester level. |
year_level |
A boolean, include year level. |
A when
object.
Other dimension definition:
define_characteristics()
,
define_instances()
,
get_attribute_definition_function()
,
get_day_part()
,
get_week_date_range()
,
select_day_level()
,
select_month_level()
,
select_quarter_level()
,
select_semester_level()
,
select_time_level()
,
select_week_level()
,
select_year_level()
,
set_attribute_definition_function()
,
set_day_part()
,
when()
td <- when() |> select_date_levels(week_level = FALSE)
td <- when() |> select_date_levels(week_level = FALSE)
When the dimension is defined as a date type, using this function we can select the day level and its attributes to include in it: date, month_day, week_day, quarter_day and year_day.
select_day_level( td, include_all, exclude_all, date, month_day, week_day, day_name, day_num_name, day_abbr, day_num_abbr, quarter_day, year_day ) ## S3 method for class 'when' select_day_level( td, include_all = FALSE, exclude_all = FALSE, date = NULL, month_day = NULL, week_day = NULL, day_name = NULL, day_num_name = NULL, day_abbr = NULL, day_num_abbr = NULL, quarter_day = NULL, year_day = NULL )
select_day_level( td, include_all, exclude_all, date, month_day, week_day, day_name, day_num_name, day_abbr, day_num_abbr, quarter_day, year_day ) ## S3 method for class 'when' select_day_level( td, include_all = FALSE, exclude_all = FALSE, date = NULL, month_day = NULL, week_day = NULL, day_name = NULL, day_num_name = NULL, day_abbr = NULL, day_num_abbr = NULL, quarter_day = NULL, year_day = NULL )
td |
A |
include_all |
A boolean, include all fields of the level. |
exclude_all |
A boolean, exclude all fields of the level. |
date |
A boolean, include the date. |
month_day |
A boolean, include the day number in the month. |
week_day |
A boolean, the day number in the week. |
day_name |
A boolean, include the name of the day of the week. |
day_num_name |
A boolean, include the number and name of the day of the week. |
day_abbr |
A boolean, include the name of the day of the week in abbreviated version. |
day_num_abbr |
A boolean, include the number and name of the day of the week in abbreviated version. |
quarter_day |
A boolean, include the number of the day in the quarter. |
year_day |
A boolean, include the number of the day in the year. |
The include_all
and exclude_all
parameters allow us to include or exclude
all attributes, and then specifically exclude or include the ones we need.
For the week_day we have the day number, its name and the name abbreviation. So that the order of the names corresponds to the alphabetical order, the combination of day number and name and/or abbreviation is included.
A when
object.
Other dimension definition:
define_characteristics()
,
define_instances()
,
get_attribute_definition_function()
,
get_day_part()
,
get_week_date_range()
,
select_date_levels()
,
select_month_level()
,
select_quarter_level()
,
select_semester_level()
,
select_time_level()
,
select_week_level()
,
select_year_level()
,
set_attribute_definition_function()
,
set_day_part()
,
when()
td <- when() |> select_day_level(day_abbr = FALSE, day_num_abbr = FALSE)
td <- when() |> select_day_level(day_abbr = FALSE, day_num_abbr = FALSE)
When the dimension is defined as a date type, using this function we can select the month level and its attributes to include in it. We can also obtain the combination of the year with the month number.
select_month_level( td, include_all, exclude_all, month, year_month, month_name, month_num_name, month_abbr, month_num_abbr ) ## S3 method for class 'when' select_month_level( td, include_all = FALSE, exclude_all = FALSE, month = NULL, year_month = NULL, month_name = NULL, month_num_name = NULL, month_abbr = NULL, month_num_abbr = NULL )
select_month_level( td, include_all, exclude_all, month, year_month, month_name, month_num_name, month_abbr, month_num_abbr ) ## S3 method for class 'when' select_month_level( td, include_all = FALSE, exclude_all = FALSE, month = NULL, year_month = NULL, month_name = NULL, month_num_name = NULL, month_abbr = NULL, month_num_abbr = NULL )
td |
A |
include_all |
A boolean, include all fields of the level. |
exclude_all |
A boolean, exclude all fields of the level. |
month |
A boolean, include the month number. |
year_month |
A boolean, include the year-month combination. |
month_name |
A boolean, include the month name. |
month_num_name |
A boolean, include the month number and name. |
month_abbr |
A boolean, include the month name abbreviated version. |
month_num_abbr |
A boolean, include the month number and name abbreviated version. |
For the month we have the month number in the year, its name and the abbreviation of the name. So that the order of the names corresponds to the alphabetical order, the combination of month number and name and/or abbreviation is included.
The include_all
and exclude_all
parameters allow us to include or exclude
all attributes, and then specifically exclude or include the ones we need.
A when
object.
Other dimension definition:
define_characteristics()
,
define_instances()
,
get_attribute_definition_function()
,
get_day_part()
,
get_week_date_range()
,
select_date_levels()
,
select_day_level()
,
select_quarter_level()
,
select_semester_level()
,
select_time_level()
,
select_week_level()
,
select_year_level()
,
set_attribute_definition_function()
,
set_day_part()
,
when()
td <- when() |> select_month_level(month_abbr = FALSE, month_num_abbr = FALSE)
td <- when() |> select_month_level(month_abbr = FALSE, month_num_abbr = FALSE)
When the dimension is defined as a date type, using this function we can select the quarter level and its attributes to include in it: quarter number and the combination of the year with it.
select_quarter_level(td, include_all, exclude_all, quarter, year_quarter) ## S3 method for class 'when' select_quarter_level( td, include_all = FALSE, exclude_all = FALSE, quarter = NULL, year_quarter = NULL )
select_quarter_level(td, include_all, exclude_all, quarter, year_quarter) ## S3 method for class 'when' select_quarter_level( td, include_all = FALSE, exclude_all = FALSE, quarter = NULL, year_quarter = NULL )
td |
A |
include_all |
A boolean, include all fields of the level. |
exclude_all |
A boolean, exclude all fields of the level. |
quarter |
A boolean, include the quarter field. |
year_quarter |
A boolean, include the quarter field. |
The include_all
and exclude_all
parameters allow us to include or exclude
all attributes, and then specifically exclude or include the ones we need.
A when
object.
Other dimension definition:
define_characteristics()
,
define_instances()
,
get_attribute_definition_function()
,
get_day_part()
,
get_week_date_range()
,
select_date_levels()
,
select_day_level()
,
select_month_level()
,
select_semester_level()
,
select_time_level()
,
select_week_level()
,
select_year_level()
,
set_attribute_definition_function()
,
set_day_part()
,
when()
td <- when() |> select_quarter_level(quarter = FALSE)
td <- when() |> select_quarter_level(quarter = FALSE)
When the dimension is defined as a date type, using this function we can select the semester level and its attributes to include in it: semester number and the combination of the year with it.
select_semester_level(td, include_all, exclude_all, semester, year_semester) ## S3 method for class 'when' select_semester_level( td, include_all = FALSE, exclude_all = FALSE, semester = NULL, year_semester = NULL )
select_semester_level(td, include_all, exclude_all, semester, year_semester) ## S3 method for class 'when' select_semester_level( td, include_all = FALSE, exclude_all = FALSE, semester = NULL, year_semester = NULL )
td |
A |
include_all |
A boolean, include all fields of the level. |
exclude_all |
A boolean, exclude all fields of the level. |
semester |
A boolean, include the semester field. |
year_semester |
A boolean, include the semester field. |
The include_all
and exclude_all
parameters allow us to include or exclude
all attributes, and then specifically exclude or include the ones we need.
A when
object.
Other dimension definition:
define_characteristics()
,
define_instances()
,
get_attribute_definition_function()
,
get_day_part()
,
get_week_date_range()
,
select_date_levels()
,
select_day_level()
,
select_month_level()
,
select_quarter_level()
,
select_time_level()
,
select_week_level()
,
select_year_level()
,
set_attribute_definition_function()
,
set_day_part()
,
when()
td <- when() |> select_semester_level(semester = FALSE)
td <- when() |> select_semester_level(semester = FALSE)
When the dimension is defined as a time type, using this function we can select the level and its attributes to include in it: time, minute, second and day_part.
select_time_level(td, include_all, exclude_all, time, minute, second, day_part) ## S3 method for class 'when' select_time_level( td, include_all = FALSE, exclude_all = FALSE, time = NULL, minute = NULL, second = NULL, day_part = NULL )
select_time_level(td, include_all, exclude_all, time, minute, second, day_part) ## S3 method for class 'when' select_time_level( td, include_all = FALSE, exclude_all = FALSE, time = NULL, minute = NULL, second = NULL, day_part = NULL )
td |
A |
include_all |
A boolean, include all fields of the level. |
exclude_all |
A boolean, exclude all fields of the level. |
time |
A boolean, include a field for the time. |
minute |
A boolean, include the minute level of detail. |
second |
A boolean, include the second level of detail. |
day_part |
A boolean, include the parts of the day. |
The 'hour' attribute will always be included. If the 'minute' attribute is not included the 'second' attribute will not be included either.
A when
object.
Other dimension definition:
define_characteristics()
,
define_instances()
,
get_attribute_definition_function()
,
get_day_part()
,
get_week_date_range()
,
select_date_levels()
,
select_day_level()
,
select_month_level()
,
select_quarter_level()
,
select_semester_level()
,
select_week_level()
,
select_year_level()
,
set_attribute_definition_function()
,
set_day_part()
,
when()
td <- when() |> select_time_level(day_part = FALSE)
td <- when() |> select_time_level(day_part = FALSE)
When the dimension is defined as a date type, using this function we can select the week level and its attributes to include in it: week and year_week.
select_week_level(td, include_all, exclude_all, week, year_week) ## S3 method for class 'when' select_week_level( td, include_all = FALSE, exclude_all = FALSE, week = NULL, year_week = NULL )
select_week_level(td, include_all, exclude_all, week, year_week) ## S3 method for class 'when' select_week_level( td, include_all = FALSE, exclude_all = FALSE, week = NULL, year_week = NULL )
td |
A |
include_all |
A boolean, include all fields of the level. |
exclude_all |
A boolean, exclude all fields of the level. |
week |
A boolean, include the week number. |
year_week |
A boolean, include the year-week combination. |
The include_all
and exclude_all
parameters allow us to include or exclude
all attributes, and then specifically exclude or include the ones we need.
For the first and last days of the year, the year associated with the week may be different from the year of the date, depending on the date type selected.
The week number associated with each date depends on the type of date dimension selected: standard ('date'), ISO 8601 ('iso') or epidemiological ('epi').
The standard week numbers blocks of 7 days beginning on January 1. The last week of the year can be less than 7 days long.
The ISO 8601 week numbers blocks of 7 days from Monday to Sunday. The first and last week of the year can contain days from the previous or next year.
The epidemiological week is like ISO 8601 only that it considers that the week begins on Sunday.
A when
object.
Other dimension definition:
define_characteristics()
,
define_instances()
,
get_attribute_definition_function()
,
get_day_part()
,
get_week_date_range()
,
select_date_levels()
,
select_day_level()
,
select_month_level()
,
select_quarter_level()
,
select_semester_level()
,
select_time_level()
,
select_year_level()
,
set_attribute_definition_function()
,
set_day_part()
,
when()
td <- when() |> select_week_level(year_week = FALSE)
td <- when() |> select_week_level(year_week = FALSE)
When the dimension is defined as a date type, using this function we can select the year level and its attributes to include in it: year and decade.
select_year_level(td, include_all, exclude_all, year, decade) ## S3 method for class 'when' select_year_level( td, include_all = FALSE, exclude_all = FALSE, year = NULL, decade = NULL )
select_year_level(td, include_all, exclude_all, year, decade) ## S3 method for class 'when' select_year_level( td, include_all = FALSE, exclude_all = FALSE, year = NULL, decade = NULL )
td |
A |
include_all |
A boolean, include all fields of the level. |
exclude_all |
A boolean, exclude all fields of the level. |
year |
A boolean, include the year field. |
decade |
A boolean, include the decade field. |
The include_all
and exclude_all
parameters allow us to include or exclude
all attributes, and then specifically exclude or include the ones we need.
A when
object.
Other dimension definition:
define_characteristics()
,
define_instances()
,
get_attribute_definition_function()
,
get_day_part()
,
get_week_date_range()
,
select_date_levels()
,
select_day_level()
,
select_month_level()
,
select_quarter_level()
,
select_semester_level()
,
select_time_level()
,
select_week_level()
,
set_attribute_definition_function()
,
set_day_part()
,
when()
td <- when() |> select_year_level(decade = FALSE)
td <- when() |> select_year_level(decade = FALSE)
Each attribute is defined by a function that adds a column to a table based on the parameter that contains the date or time. This function sets the definition function for the attribute whose name is given.
set_attribute_definition_function(td, name, f) ## S3 method for class 'when' set_attribute_definition_function(td, name = NULL, f = NULL)
set_attribute_definition_function(td, name, f) ## S3 method for class 'when' set_attribute_definition_function(td, name = NULL, f = NULL)
td |
A |
name |
A string, attribute name. |
f |
A function. |
A when
object.
Other dimension definition:
define_characteristics()
,
define_instances()
,
get_attribute_definition_function()
,
get_day_part()
,
get_week_date_range()
,
select_date_levels()
,
select_day_level()
,
select_month_level()
,
select_quarter_level()
,
select_semester_level()
,
select_time_level()
,
select_week_level()
,
select_year_level()
,
set_day_part()
,
when()
f <- function(table, values, ...) { table[['year']] <- 'Not defined' table } wd <- when() |> set_attribute_definition_function(name = "year", f)
f <- function(table, values, ...) { table[['year']] <- 'Not defined' table } wd <- when() |> set_attribute_definition_function(name = "year", f)
Using this function we can change the name assigned to the hours of the day to designate the parts of the day.
set_day_part(td, hour, name) ## S3 method for class 'when' set_day_part(td, hour = NULL, name = NULL)
set_day_part(td, hour, name) ## S3 method for class 'when' set_day_part(td, hour = NULL, name = NULL)
td |
A |
hour |
A number, hour number (between 0 and 23). |
name |
a string, name of the part of the day. |
A when
object.
Other dimension definition:
define_characteristics()
,
define_instances()
,
get_attribute_definition_function()
,
get_day_part()
,
get_week_date_range()
,
select_date_levels()
,
select_day_level()
,
select_month_level()
,
select_quarter_level()
,
select_semester_level()
,
select_time_level()
,
select_week_level()
,
select_year_level()
,
set_attribute_definition_function()
,
when()
td <- when() |> set_day_part(hour = c(21:23, 0:4), name = "Night")
td <- when() |> set_day_part(hour = c(21:23, 0:4), name = "Night")
Rename the attributes of the dimension table. It is especially useful if we want to export the table, for example, to a database.
set_table_attribute_names(td, names) ## S3 method for class 'when' set_table_attribute_names(td, names = NULL)
set_table_attribute_names(td, names) ## S3 method for class 'when' set_table_attribute_names(td, names = NULL)
td |
A |
names |
A string vector. |
A when
object.
Other obtaining results:
generate_table()
,
get_level_attribute_names()
,
get_level_names()
,
get_table_attribute_names()
wd <- when() |> generate_table() wd |> get_table_attribute_names() wd <- wd |> set_table_attribute_names( c( 'id_when', 'date', 'month_day', 'week_day', 'day_name', 'day_num_name', 'year_week', 'week', 'year_month', 'month', 'month_name', 'month_num_name', 'year' ) )
wd <- when() |> generate_table() wd |> get_table_attribute_names() wd <- wd |> set_table_attribute_names( c( 'id_when', 'date', 'month_day', 'week_day', 'day_name', 'day_num_name', 'year_week', 'week', 'year_month', 'month', 'month_name', 'month_num_name', 'year' ) )
Time in seconds of a day
time_seconds
time_seconds
A vector.
Other time definition:
date_days
when
S3 classCreates a when
object.
when( name = NULL, type = NULL, locale = NULL, start = lubridate::today(), end = lubridate::today(), values = NULL, ... )
when( name = NULL, type = NULL, locale = NULL, start = lubridate::today(), end = lubridate::today(), values = NULL, ... )
name |
A string, table name. |
type |
A string, type of calendar (NULL, 'iso', 'epi' or 'time'). |
locale |
A locale, to use for day and month names. |
start |
A string, start of the period to be included in the dimension. |
end |
A string, end of the period to be included in the dimension. |
values |
A vector of string. |
... |
Rest of boolean configuration parameters. |
Using the parameters of this function we can configure practically all the elements of the dimension. Alternatively, we can use the configuration functions to define the available options.
We discuss the parameters in each of the specific configuration functions.
A when
object.
Other dimension definition:
define_characteristics()
,
define_instances()
,
get_attribute_definition_function()
,
get_day_part()
,
get_week_date_range()
,
select_date_levels()
,
select_day_level()
,
select_month_level()
,
select_quarter_level()
,
select_semester_level()
,
select_time_level()
,
select_week_level()
,
select_year_level()
,
set_attribute_definition_function()
,
set_day_part()
td_1 <- when() td_2 <- when(type = 'time')
td_1 <- when() td_2 <- when(type = 'time')