Skip to content

Feature request: flexibility of date and time transformations w.r.t. numeric input. #298

@teunbrand

Description

@teunbrand

Originally discussed in tidyverse/ggplot2#980 (comment); it seems as there is some need for flexibility of date and time transformations. These transformations are currently harder to program with than plain numerical transformations, as the date/time transformations have strict requirements on the class of the input data.

@yutannihilation made two excellent suggestions which I'll repeat here.

  1. Let the domain part of the transformation be of the same class as the expected input data. This in particular would allow a solution to a longstanding issue in ggplot2.
  2. Let date_trans()$transform() and time_trans()$transform() accept numeric values. This would solve the aforementioned issue, as well as some others.

I understand that the class requirements protect against unintentional mistakes so I'd like to mention a 3rd idea.

  1. Add ... arguments to all trans$transform() arguments and in addition a force argument to the date/time transforms. The logic then could be as follows:
function(x, force = FALSE, ...)  
{
  if (!inherits(x, "Date") & !force) {
    stop("Invalid input: date_trans works with objects of class Date only", 
         call. = FALSE)
  }
  structure(as.numeric(x), names = names(x))
}

This would allow only the transformation of intentional numeric values while still raising the error upon unintentional input.

Thanks for reading!

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancementhelp wanted ❤️we'd love your help!

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions