| parse_tag | R Documentation |
Sources often give dates as if they were precise when they are not.
For example, a dataset can have an arbitrary cut-off point for start
and end dates.
The tag_*() functions add the ISO 8601-2:2019(E) notation for
this information to dates.
Each tag_*() function has a matching date_is_*() test
(see operate_statements).
tag_approximate() adds a tilde, ~, for a date or component that
is possibly correct (e.g. 2003-03-~03 or 2003-03-03~).
Test with date_is_approximate().
tag_uncertain() adds a question mark, ?, for a date or component
that is possibly incorrect (e.g. 1916-10-?10 or 1916-10-10?).
A date that is approximate and uncertain gets %.
Test with date_is_uncertain().
tag_unspecified() replaces the digits of a component with X
(e.g. 2012-XX-15). This discards the digits.
A trailing unspecified component is kept as XX,
so tag_unspecified("2012-06-15", "day") gives 2012-06-XX.
Test with !date_is_precise().
tag_before() makes a date into an open range that means
"on or before" this date (e.g. ..1816-01-01).
It does not mean "strictly before".
Test with date_is_open().
tag_after() makes a date into an open range that means
"on or after" this date (e.g. 2016-12-31..).
Test with date_is_open().
untag() removes the tags that tags names.
It cannot remove X, because tag_unspecified() discards the digits.
The empty set, {}, and NA do not change.
tag_approximate(x, component = NULL)
tag_uncertain(x, component = NULL)
tag_unspecified(x, component)
tag_before(x)
tag_after(x)
untag(x, tags = c("approximate", "uncertain", "before", "after"))
x |
A date vector. |
component |
The component to tag:
"year", "month" or "day", or a group of date components:
month and day ("md"), year and month ("ym"), or all of them ("date").
For date-times, |
tags |
The tags that |
An mdate object.
data <- data.frame(Beg = c("1816-01-01", "1916-01-01", "2016-01-01"),
End = c("1816-12-31", "1916-12-31", "2016-12-31"))
transform(data, Beg = ifelse(Beg <= "1816-01-01",
as.character(tag_before(Beg)), Beg))
transform(data, End = ifelse(End >= "2016-01-01",
as.character(tag_after(End)), End))
transform(data, Beg = ifelse(Beg == "1916-01-01",
as.character(tag_approximate(Beg)), Beg))
transform(data, End = ifelse(End == "1916-12-31",
as.character(tag_uncertain(End)), End))
tag_approximate("2012-06-15")
tag_approximate("2012-06-15", "date")
tag_uncertain(tag_approximate("2012-06-15"))
tag_unspecified("2012-06-15", "day")
# time components can be tagged too
tag_approximate("2019-03-01 14:30:00", "hour")
tag_uncertain("2019-03-01 14:30:00", "second")
# remove tags
untag(c("2019-03-01%", "..2019-03-01"))
untag("2019-03-01%", "approximate")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.