2

Im tring to use the bizdays package to generate a vector with bus days between two dates.

fer = as.data.frame(as.Date(fer[1:938]))

#Define default calendar
bizdays.options$set(default.calendar=fer)

dt1 = as.Date(Sys.Date())
dt2 = as.Date(Sys.Date()-(365*10)) #sample 10 year window

#Create date vector
datas = bizseq(dt2, dt1)

i get this error: "Error in bizseq.Date(dt2, dt1) : Given date out of range." the same behavior for any function bizdays et al.

any ideas?

www
  • 38,575
  • 12
  • 48
  • 84
Alexandre Ludolf
  • 196
  • 1
  • 10

2 Answers2

4

I had a similar problem, but could not apply the accepted answer to my case. What worked for me was to make sure that the first and last holiday in the vector holidays at least covers (or exceeds) the range of dates provided to bizdays():

   library(bizdays)

This works (from_date and to_date both lie within the first and last holiday provided by holidays):

   holidays <- c("2016-08-10", "2016-08-13")

    from_date <- "2016-08-11"
    to_date <- "2016-08-12"

    cal <- Calendar(holidays, weekdays=c('sunday', 'saturday'))
    bizdays(from_date, to_date, cal)

    #1

This does not work (to_date lies outside of the last holiday of holidays):

    holidays <- c("2016-08-10", "2016-08-11")

    from_date <- "2016-08-11"
    to_date <- "2016-08-12"

    cal <- Calendar(holidays, weekdays=c('sunday', 'saturday'))
    bizdays(from_date, to_date, cal)

   # Error in bizdays.Date(from, to, cal) : Given date out of range.
Flo
  • 1,503
  • 1
  • 18
  • 35
0

If fer is the holidays, you can try with:

bizdays.options$set(default.calendar=Calendar(holidays=fer))
HubertL
  • 19,246
  • 3
  • 32
  • 51
  • Tks HubertL, your solution worked! had to set the weekends as well: bizdays.options$set(default.calendar=Calendar(holidays=fer, weekdays=c("saturday", "sunday"))) – Alexandre Ludolf Jul 04 '16 at 22:28