Last active
April 15, 2024 16:20
-
-
Save rudeboybert/ebf39a24a03216be55cb20d9c475f57d to your computer and use it in GitHub Desktop.
Code to import a Google Calendar, macOS Calendar, or Outlook calendar .ics file into R
This file contains 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
library(ggplot2) | |
library(dplyr) | |
library(lubridate) | |
library(ical) | |
# For a screencast demo on creating a calendar and exporting it to .ics file format | |
# see this video: https://youtu.be/vLlR4lBWAoc | |
# Locate your .ics calendar file on your computer and change what's in quotation marks | |
calendar_data <- "192.ics" %>% | |
# Use ical package to import into R and then convert to "tibble" data frame format: | |
ical_parse_df() %>% | |
as_tibble() %>% | |
# Use lubridate packge to wrangle dates and times. We'll do this later this semester: | |
mutate( | |
start_datetime = with_tz(start, tzone = "America/New_York"), | |
end_datetime = with_tz(end, tzone = "America/New_York"), | |
minutes = end_datetime - start_datetime, | |
date = floor_date(start_datetime, unit = "day") | |
) %>% | |
# Make calendar entry summary all lowercase: | |
mutate(summary = tolower(summary)) %>% | |
# Do data wrangling to compute number of minutes and hours: | |
group_by(date, summary) %>% | |
summarize(minutes = sum(minutes)) %>% | |
mutate( | |
minutes = as.numeric(minutes), | |
hours = minutes/60 | |
) %>% | |
# New: Filter out only rows where date is later than 2019-09-01 | |
filter(date > "2019-09-01") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment