calendar allows
you to read-in ‘ical files’ (which typically have the .ics
filetype) with ic_read()
. However, often it’s useful to
create your own ical
object from scratch. The purpose of
this vignette is to show how, with reference to a real-world
application: creating a timetable for a new module.
It assumes you’ve installed the package following instructions in the README and have attached it as follows:
The building blocks of most calendars the event. All events have a start point and an end point (unless they are an all day event) and a summary description. As shown in the example below, they also tend to contain other fields.
# key:value pairs in an ical example:
ic_list(ical_example)[[1]]
#> [1] "DTSTART:20180809T160000Z"
#> [2] "DTEND:20180809T163000Z"
#> [3] "DTSTAMP:20180810T094100Z"
#> [4] "UID:[email protected]"
#> [5] "CREATED:20180807T133712Z"
#> [6] "DESCRIPTION:\\n"
#> [7] "LAST-MODIFIED:20180807T133712Z"
#> [8] "LOCATION:"
#> [9] "SEQUENCE:0"
#> [10] "STATUS:CONFIRMED"
#> [11] "SUMMARY:ical programming mission"
#> [12] "TRANSP:OPAQUE"
Fortunately you don’t need to specify all of these when creating events because some will be created manually and some are not necessary. Events can be created as follows (this one creates a 5 day trip):
library(calendar)
s = as.POSIXct("2019-01-12")
e = s + 60^2 * 24 *5
event = ic_event(start = s, end = e , summary = "Research trip")
event
#> # A tibble: 1 × 4
#> UID DTSTART DTEND SUMMARY
#> <chr> <dttm> <dttm> <chr>
#> 1 ical-c31606dc-c2c3-40ca-88d4-… 2019-01-12 00:00:00 2019-01-17 00:00:00 Resear…
class(event)
#> [1] "ical" "tbl_df" "tbl" "data.frame"
ic_character(event)
#> [1] "BEGIN:VCALENDAR"
#> [2] "PRODID:-//ATFutures/ical //EN"
#> [3] "VERSION:2.0"
#> [4] "CALSCALE:GREGORIAN"
#> [5] "METHOD:PUBLISH"
#> [6] "BEGIN:VEVENT"
#> [7] "UID:ical-c31606dc-c2c3-40ca-88d4-5bab0ef36b08"
#> [8] "DTSTART:20190112T000000"
#> [9] "DTEND:20190117T000000"
#> [10] "SUMMARY:Research trip"
#> [11] "END:VEVENT"
#> [12] "END:VCALENDAR"