ImperialCollegeLondon / epidemia

epidemia package
https://imperialcollegelondon.github.io/epidemia/index.html
47 stars 15 forks source link

plot_obs date range does not accept Date object and NA #37

Closed agandy closed 4 years ago

agandy commented 4 years ago

from the examples of plot_obs

plot_obs(fit, type="deaths", dates=c(as.Date("2020-03-21"), NA)) # plot 21 March 2020 onwards works as expected, but changing the dates argument to be a "Date" object leads to an error !> plot_obs(fit, type="deaths", dates=c(as.Date("2020-03-21"), NA)) # plot 21 March 2020 onwards Error in to0 - from : non-numeric argument to binary operator

agandy commented 4 years ago

@jonathanishhorowicz - could you look at this at your leisure?

jonathanishhorowicz commented 4 years ago

Will have a look now

jonathanishhorowicz commented 4 years ago

I have fixed the case you have posted here, but the reverse case

plot_obs(fit, type="deaths", dates=c(NA, as.Date("2020-03-21")))

ie when dates is c(NA, a date object) is a little more tricky. Having NA as the first element makes the whole dates vector become numeric and converting this back to a date means specifying the date origin.

To me it seems easier and less buggy to ask the user to to as.Date on the whole of dates rather than a single element.

agandy commented 4 years ago

Thanks. Happy with any solution, as long as there is a meaningful error message. A

From: Jonathan Ish-Horowicz notifications@github.com Sent: 15 July 2020 12:23 To: ImperialCollegeLondon/epidemia epidemia@noreply.github.com Cc: Gandy, Axel a.gandy@imperial.ac.uk; Author author@noreply.github.com Subject: Re: [ImperialCollegeLondon/epidemia] plot_obs date range does not accept Date object and NA (#37)

This email from notifications@github.commailto:notifications@github.com originates from outside Imperial. Do not click on links and attachments unless you recognise the sender. If you trust the sender, add them to your safe senders listhttps://spam.ic.ac.uk/SpamConsole/Senders.aspx to disable email stamping for this address.

I have fixed the case you have posted here, but the reverse case

plot_obs(fit, type="deaths", dates=c(NA, as.Date("2020-03-21")))

ie when dates is c(NA, a date object) is a little more tricky. Having NA as the first element makes the whole vector become numeric and converting this back to a date means specifying the date origin.

To me it seems easier and less buggy to ask the user to to as.Date on the whole of dates rather than a single element.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/ImperialCollegeLondon/epidemia/issues/37#issuecomment-658711845, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AA7JUZW2QSWW4DRJBAJ5OBDR3WGR3ANCNFSM4O2K7P3Q.