I am trying to write a function that, given a date start
and an integer n
, adds n
months to the date and then takes the last day of the resulting month.
The following piece of code, however, returns NA
for n=8+12k
, but seems to work in other cases.
library(lubridate)
start <- ymd("2020-06-29")
n <- 8
floor_date(start + months(n), "month") + months(1) - days(1)
>[1] NA
I guess this is somewhat due to the existence of leap years, but I still find it puzzling. Plus, I couldn't find anything in the docs about this.
Can someone please explain what is going on, or suggest a better way to do the job?