The goal of statsAndBooze is to find the optimal date for a happy hour, i.e.Β the closest date when all the participants are available.
You can install the development version of statsAndBooze from GitHub with:
# install.packages("devtools")
devtools::install_github("Anastasia-psy/statsAndBooze")
To load the package:
library(statsAndBooze)
The input must be a list of names with the available dates for each
participant and must be transformed from string to data format. Use the
function parse_dates()
for this task.
In the list, you must specify the dates in YYYY-MM-DD
format like in
the example below:
dates<- list(
andrea = "2023-03-29", # exactly with this format
federico = "2023-03-30" # exactly with this format
)
parse_dates(dates)
#> $andrea
#> [1] "2023-03-29"
#>
#> $federico
#> [1] "2023-03-30"
You can also specify a time interval when a participant is available.
This must be done in the following format: YYYY-MM-DD / YYYY-MM-DD
(see example).
dates <- list(
andrea = c("2023-04-01", "2023-04-03 / 2023-04-05"),
federico = c("2023-04-02", "2023-04-03"),
chiara = "2023-04-02 / 2023-04-03"
)
parse_dates(dates)
#> $andrea
#> [1] "2023-04-01" "2023-04-03" "2023-04-04" "2023-04-05"
#>
#> $federico
#> [1] "2023-04-02" "2023-04-03"
#>
#> $chiara
#> [1] "2023-04-02" "2023-04-03"
You can also specify the dates using the workdays names in your local
language in the abbreviated form. To see the available values for days
of week, run the function lubridate::wday(x, label = TRUE)
.The names
of the weekdays refer to the subsequent 7 days with respect to the
current day (included) when the function is run. For each person the
dates must be specified or in date form or as days of the week, but not
in a mixed form. See the following example:
lubridate::wday("2023-04-28", label = TRUE)
#> [1] ven
#> Levels: dom < lun < mar < mer < gio < ven < sab
dates <- list(
andrea = c("sab", "gio", "dom"),
federico = c("2023-04-27", "2023-04-30"),
chiara = "2023-04-28 / 2023-04-30"
)
parse_dates(dates)
#> $andrea
#> [1] "2023-04-29" "2023-04-30" "2023-05-04"
#>
#> $federico
#> [1] "2023-04-27" "2023-04-30"
#>
#> $chiara
#> [1] "2023-04-28" "2023-04-29" "2023-04-30"
Finally, to define the date for a happy hour, you need the function
decide_happy_hour()
, which takes the output of the function
parse_dates
as input. In case there are several dates when all the
participants are available, the function returns the nearest suitable
date. See the example below.
dates <- list(
andrea = c("sab", "gio", "dom"),
federico = c("2023-04-27", "2023-04-30"),
chiara = "2023-04-28 / 2023-04-30"
)
parsed_dates <- parse_dates(dates)
decide_happy_hour(parsed_dates)
#> [1] "2023-04-30"
The function returns Date of length 0
if there is no date when all the
participants are available.