0

I'm puzzled by the following code, which was working yesterday:

> Sys.Date() - months(13)
[1] NA

Why does it return NA? These experiments fail to answer my question:

> Sys.Date() + months(13)
[1] "2016-08-31"
> Sys.Date() - months(13)
[1] NA
> Sys.Date() - months(12)
[1] "2014-07-31"
> Sys.Date() - months(12) - months(1)
[1] NA
> Sys.Date() - months(15)
[1] NA
> Sys.Date() - years(1)
[1] "2014-07-31"
> Sys.Date() +days(1) - months(13)
[1] "2014-07-01"
John David Smith
  • 573
  • 1
  • 6
  • 15
  • 3
    You don't really state a question. What's your expected result? Remember, "30 days have September, April, June and November". – Gregor Thomas Jul 31 '15 at 18:08
  • 1
    The argument to `months` is supposed to be a Date-classed object. – IRTFM Jul 31 '15 at 18:08
  • @BondedDust with this usage, OP is probably using `lubridate` as indicated in the tag. – Gregor Thomas Jul 31 '15 at 18:08
  • @Gregor: I thought something like that might be happening, and had started a comment that asked for edit to include any needed `library` calls, but discovered (to my surprise) that there already is a `base::months` function. – IRTFM Jul 31 '15 at 18:12
  • @Gregor: How can I transfer 5000 rep to you? You clearly deserve the ability to wield the close-hammer. – IRTFM Jul 31 '15 at 18:18
  • @BondedDust aww, thanks--that put a big smile on my face :) You could always go through my answer history upvoting some under-appreciated gems (though I don't think you can do it too quickly). – Gregor Thomas Jul 31 '15 at 18:27
  • I think I may do that. I've got lots of time and I'll probably learn some useful tricks. – IRTFM Jul 31 '15 at 18:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/84840/discussion-between-gregor-and-bondeddust). – Gregor Thomas Jul 31 '15 at 18:36
  • 2
    Thanks for pointing me in the right direction @Gregor and BondedDust. As so often in R, the answer is obvious after you know, but knowing exactly how to ask it is not. – John David Smith Jul 31 '15 at 21:38
  • @JohnDavidSmtih: Very TRUE. I've developed the strategy of immediately closing "with extreme prejudice" questions where the keywords in the title do yield good answers on an SO search, but being more lenient with those that do not. On the other hand, wnhen someone else nominates an existing question, I visit that question and upvote the questioner and the answerer. – IRTFM Aug 01 '15 at 03:57

0 Answers0