Created
January 13, 2024 03:56
-
-
Save cynthiahqy/fbbdeff61372c5bda80277eacaf62100 to your computer and use it in GitHub Desktop.
create 2024 date table for notion import
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# code to generate csv file of dates to import into notion database | |
library(tibble) | |
library(dplyr) | |
library(lubridate) | |
library(stringr) | |
df_2024 <- tibble( | |
ymd = seq(as.Date("2024-01-01"), as.Date("2024-12-31"), by = "days") | |
) |> | |
## these three mutate calls do the same thing in different ways | |
mutate(wday_md = paste0( | |
wday(ymd, label = TRUE), ", ", | |
month(ymd, label = TRUE), " ", | |
str_pad(day(ymd), width = 2, pad = "0") | |
)) |> | |
mutate(wday_glue = glue::glue( | |
"{wday(ymd, label = TRUE)}, \\ | |
{month(ymd, label = TRUE)} \\ | |
{str_pad(day(ymd), 2, pad = '0')}" | |
)) |> | |
mutate(wday_format = format(ymd, "%a, %b %d")) |> | |
## week returns no of complete seven day periods since Jan 1 | |
## might need to use isoweek() instead for years not beginning on a Monday | |
mutate(week_no = week(ymd)) |> | |
## generate week number labels with start-end dates e.g. W01: Jan 01-07 | |
group_by(week_no) |> | |
mutate( | |
week_start = min(ymd), | |
week_end = max(ymd), | |
same_month = identical( | |
month(week_start), | |
month(week_end) | |
) | |
) |> | |
mutate(week_dates = if_else(same_month, | |
glue::glue( | |
"{format(week_start, '%b %d')}-{format(week_end, '%d')}" | |
), | |
glue::glue( | |
"{format(week_start, '%b %d')}-{format(week_end, '%b %d')}" | |
) | |
)) |> | |
mutate(week_glue = glue::glue( | |
"W{str_pad(week_no, 2, pad = '0')}: {week_dates}" | |
)) |> | |
ungroup() | |
## export only the columns needed | |
export_2024 <- | |
transmute(df_2024, | |
name = wday_format, | |
date = format(ymd, "%Y-%m-%d"), | |
week = week_glue | |
) | |
## write to csv, then import into notion | |
export_2024 |> | |
write.csv(here::here("day_2024.csv"), row.names = FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@bennywee