knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The goal of calendar is to make it easy to create, read, write, and work with iCalander (.ics
, .ical
or similar) files, and the scheduling data they represent, in R.
iCalendar is an open standard for
"exchanging calendar and scheduling information between users and computers"
described at icalendar.org (the full spec can be found in a
plain text file here).
Recently the UK Government endorsed the iCal format in a publication for the 'Open Standards for Government' series. An example .ics file is provided by the .gov.uk domain, which shows holidays in England and Wales.
install.packages("calendar")
Or install the cutting edge from GitHub
devtools::install_github("ATFutures/calendar")
library(calendar)
A minimal example representing the contents of an iCalendar file is provided in the dataset ical_example
, which is loaded when the package is attached.
This is what iCal files look like:
ical_example
Relevant fields can be found and extracted as follows:
which(ic_find(ical_example, "TSTAMP")) ic_extract(ical_example, "TSTAMP")
A larger example shows all national holidays in England and Wales. It can be read-in as follows:
ics_file <- system.file("extdata", "england-and-wales.ics", package = "calendar") ics_raw = readLines(ics_file) head(ics_raw) # check it's in the ICS format
A list representation of the calendar can be created using ic_list()
as follows:
ics_list = ic_list(ics_raw) ics_list[1:2]
A data frame representing the calendar can be created as follows (work in progress):
ics_df = ic_read(ics_file) # read it in head(ics_df) # check the results
What class is each column?
vapply(ics_df, class, character(1))
To make the package robust we test on a wide range of ical formats. Here's an example from my work calendar, for example:
my_cal = ic_dataframe(ical_outlook) my_cal$SUMMARY[1] # calculate the duration of the European R users meeting event: my_cal$`DTEND;VALUE=DATE`[1] - my_cal$`DTSTART;VALUE=DATE`[1]
my_cal = ic_read("https://outlook.office365.com/owa/calendar/63f6c4e85d124df6a20656ade8e71faa@leeds.ac.uk/32e1cb4137f4414b8d7644453ec4b10414316826143036893453/calendar.ics") attributes(my_cal)$ical # head(my_cal[c("DESCRIPTION", "SUMMARY", "DTSTART", "DTEND", "STATUS", "SEQUENCE", "LOCATION")])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.