knitr::opts_chunk$set( collapse = TRUE, comment = "#>", out.width = "100%" ) library(daily) library(dplyr)
The primary use case consists of three steps
daily2cal()
Steps 2 and 3 can be combined into a single step.
Calendar information can be culled from a "daily file" with with following structure.
Days are separated by an initial ===
===
may optionally be followed by a date===endofcal
terminates the calendar. All lines after are ignored.<item type>:: <item information>
is rendered as information on
a specific date. For the HTML version, this is converted into a span
so that the appearance can be altered using CSS.
<item type>
is ignored.::
is required.daily2html()
if ::
is needed for something else.Other lines are ignored when preparing the calendar.
Here is an example daily file (rendered below).
system.file("daily.txt", package = "daily") %>% readLines() %>% paste(collapse = "\n") %>% cat()
daily2cal()
converts the daily file into a data frame.
To use your own daily file, replace the path
argument below with
the path to your daily file.
library(daily) library(dplyr) cal <- daily2cal( path = system.file("daily.txt", package = "daily") ) glimpse(cal)
Each time a bare ===
is encountered, the calendar is advanced to the
next default day (see options below).
If a date is specified, it is used, regardless of which days are default days.
The calendar can be rendered as HTML or as a ggplot.
The show
argument determines which days are displayed (Sunday = 1,
Saturday = 7).
calendar_css() %>% cat() cal %>% html_calendar(show = 2:6) %>% cat()
cal %>% gg_calendar(show = 2:6, size = 4)
Alternatively, the daily file can be converted directly to HTML using daily2html()
:
daily2html(path = system.file("daily.txt", package = "daily")) %>% cat()
The following options may be specified as arguments to daily2cal()
or as part
of the YAML header of the daily file. Arguments take precedence over the YAML
header.
days
: default days. Can be specified as a numeric vector or as a character string (1 = N = Sunday, 5 = R = Thursday, 7 = S = Saturday, etc.)start
: start date for the calendar ("mm/dd/yyyy" format in YAML, date object as argument)end
: start date for the calendar ("mm/dd/yyyy" format in YAML, date object as argument)css
: the path to a file containing CSS for the calendar or "default"
or "none"
.
This is only used by daily2html()
. If missing, it will be treated as if the value
is "default"
, and a default CSS file is used.Other elements of the YAML header are ignored currently, but can be used to record information about your calendar.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.