Skip to contents

Get the calendar for a given month and year

Usage

get_calendar(
  year = format(Sys.Date(), "%Y"),
  month = format(Sys.Date(), "%m"),
  weekend = FALSE,
  lang = NULL
)

Arguments

year

either an integer or a character of length 1. Must have 4 characters (e.g. '2024' and not '24'). Default is the current year.

month

either an integer or a character of length 1. Must have 1 or 2 characters (e.g. '01' or '1'). Default is the current month.

weekend

a logical. If TRUE keeps Saturdays and Sundays. Default is FALSE.

lang

a character of length 1. Used to change the default locale (i.e. the language). Default is NULL (i.e. use the current locale). See examples below. Depending on the OS and the locale, the output can be weird.

Value

A data.frame with the following columns:

  • date: the date of the day (YYYY-MM-DD),

  • year: the year of the day (integer),

  • month: the month of the day (integer),

  • day: the day (integer),

  • week: the number of week (integer),

  • weekday: the name of the day of the week (character),

  • month_name: the name of month (character),

  • x: position on the x-axis (used by monthly_calendar()),

  • y: position on the y-axis (used by monthly_calendar()).

Examples

## Calendar for the current month ----
head(get_calendar())
#>         date year month day week en_weekday en_month_name user_weekday
#> 1 2024-04-01 2024     4   1   14     Monday         April       Monday
#> 2 2024-04-02 2024     4   2   14    Tuesday         April      Tuesday
#> 3 2024-04-03 2024     4   3   14  Wednesday         April    Wednesday
#> 4 2024-04-04 2024     4   4   14   Thursday         April     Thursday
#> 5 2024-04-05 2024     4   5   14     Friday         April       Friday
#> 6 2024-04-08 2024     4   8   15     Monday         April       Monday
#>   user_month_name x y
#> 1           April 1 6
#> 2           April 2 6
#> 3           April 3 6
#> 4           April 4 6
#> 5           April 5 6
#> 6           April 1 5

## Calendar for December (current year) ----
head(get_calendar(month = 12))
#>         date year month day week en_weekday en_month_name user_weekday
#> 1 2024-12-02 2024    12   2   49     Monday      December       Monday
#> 2 2024-12-03 2024    12   3   49    Tuesday      December      Tuesday
#> 3 2024-12-04 2024    12   4   49  Wednesday      December    Wednesday
#> 4 2024-12-05 2024    12   5   49   Thursday      December     Thursday
#> 5 2024-12-06 2024    12   6   49     Friday      December       Friday
#> 6 2024-12-09 2024    12   9   50     Monday      December       Monday
#>   user_month_name x y
#> 1        December 1 6
#> 2        December 2 6
#> 3        December 3 6
#> 4        December 4 6
#> 5        December 5 6
#> 6        December 1 5

## Calendar for April (current year) ----
head(get_calendar(month = 4))
#>         date year month day week en_weekday en_month_name user_weekday
#> 1 2024-04-01 2024     4   1   14     Monday         April       Monday
#> 2 2024-04-02 2024     4   2   14    Tuesday         April      Tuesday
#> 3 2024-04-03 2024     4   3   14  Wednesday         April    Wednesday
#> 4 2024-04-04 2024     4   4   14   Thursday         April     Thursday
#> 5 2024-04-05 2024     4   5   14     Friday         April       Friday
#> 6 2024-04-08 2024     4   8   15     Monday         April       Monday
#>   user_month_name x y
#> 1           April 1 6
#> 2           April 2 6
#> 3           April 3 6
#> 4           April 4 6
#> 5           April 5 6
#> 6           April 1 5

## Calendar for January 1970 ----
head(get_calendar(year = 1970, month = 1))
#>         date year month day week en_weekday en_month_name user_weekday
#> 1 1970-01-01 1970     1   1    0   Thursday       January     Thursday
#> 2 1970-01-02 1970     1   2    0     Friday       January       Friday
#> 3 1970-01-05 1970     1   5    1     Monday       January       Monday
#> 4 1970-01-06 1970     1   6    1    Tuesday       January      Tuesday
#> 5 1970-01-07 1970     1   7    1  Wednesday       January    Wednesday
#> 6 1970-01-08 1970     1   8    1   Thursday       January     Thursday
#>   user_month_name x y
#> 1         January 4 6
#> 2         January 5 6
#> 3         January 1 5
#> 4         January 2 5
#> 5         January 3 5
#> 6         January 4 5

if (FALSE) {
## Change the locale (Spanish) ----
head(get_calendar(year = 1970, month = 1, lang = "Spanish"))
}