Skip to content

rescale Date (and POSIXct) objects? #74

@zeehio

Description

@zeehio

Hi,

As of today it is not possible to rescale dates (and times) using scales::rescale. Is there a particular reason? I am puzzled by this, and I think that I must be missing something, because the problem seems fairly simple to tackle (using as.numeric somewhere). I would like to contribute with a clean solution, but I am afraid I am being naive on the solution. Any advice? (ggplot2::geom_segment could benefit from this)

days <- as.Date(c("2016-03-01", "2016-03-02", "2016-03-03"))
scales::rescale(days[2], from = c(days[1], days[3])) == 0.5

datetimes <- as.POSIXct(c("2016-03-01 08:05:00",
                          "2016-03-01 08:10:00",
                          "2016-03-01 08:15:00"),
                        format = "%Y-%m-%d %H:%M:%S")
testthat::expect_equal(scales::rescale(datetimes[2],
                       from = c(datetimes[1], datetimes[3])), 0.5)

I get

Error in Math.Date(x) : abs not defined for "Date" objects

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions