Skip to content

Commit 9aba3e9

Browse files
authored
Merge pull request #20 from Boehringer-Ingelheim/doc/date_handling
Documentation for robust_ymd.
2 parents 356a1f7 + b919b02 commit 9aba3e9

2 files changed

Lines changed: 40 additions & 3 deletions

File tree

R/utils-misc.R

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,28 @@ silence_warning <- function(expr, warning_message) {
2929

3030
merge_with_no_duplicate_cols <- function(a, b, by) merge(a, b[c(by, setdiff(names(b), names(a)))], by)
3131

32-
robust_min <- function(...) min(..., +Inf, na.rm = TRUE) # TODO: Remove if unused
33-
robust_max <- function(...) max(..., -Inf, na.rm = TRUE) # TODO: Remove if unused
34-
32+
#' Convert possibly truncated character(n) 'yyyy-mm-dd' to Date(n)
33+
#' performing optional round up using the level of precision present
34+
#' in the input data
35+
#'
36+
#' @param data [character(n)] Vector of dates
37+
#'
38+
#' @keywords internal
39+
#'
3540
robust_ymd <- function(data, round_up = FALSE) {
41+
# NOTE(miguel):
42+
# `dv.papo` used to rely on `lubridate` for date parsing.
43+
# We dropped that library because we didn't need any of its many advanced features.
44+
# Instead, we wrote this function to parse the only format we cared about ('yyyy-mm-dd'),
45+
# and to round end-dates up taking into account the unit information implicit to possibly
46+
# truncated ('yyyy', 'yyyy-mm') input strings.
47+
# Using `lubridate::ceiling_date` instead results in even more code on our part, since
48+
# that call assumes that all input dates have a homogeneous precision, which is not the case
49+
# for us.
50+
#
51+
# In any case, the point is moot because we now require users of `dv.papo` to provide Date
52+
# objects and this function is a (non-exported) helper to deal with character dates.
53+
3654
label <- attr(data, "label")
3755

3856
data <- substr(data, 1, 10)

man/robust_ymd.Rd

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)