I am unable to find what is specifically giving me this error after stepping through the code multiple times. I'm hoping that someone has seen this error before.
Here's what I think is relevant to the problem:
#### Load packages
library(lubridate)
MONTH <- 1
YEAR <- 2018
# Last day of month
last_day_of_mth <- function(YEAR, MONTH){
MONTH_BEGIN <- as.POSIXlt(paste0(YEAR, "-", MONTH, "-1"))
MONTH_END <- MONTH_BEGIN
day(MONTH_END) <- day(MONTH_BEGIN)
month(MONTH_END) <- month(MONTH_END) + 1
day(MONTH_END) <- day(MONTH_END) - 1
return(as.character(MONTH_END))
}
This code loads a bunch of external files via source()
which do not contain any other packages or other functions. They just query data from the Google Analytics API or they load .csv files, manipulate the data frames, and spit out appropriate output as .csv files.
For some bizarre reason, after running these 10 files via source()
, it spits out
> last_day_of_mth(2018, 1)
[1] "2018-03-02 06:00:00"
which is obviously not correct - it should be 2018-01-31
.