Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bizdays & bizdiff function not functioning, returning error instead. #98

Open
keegangclarke opened this issue Oct 12, 2022 · 3 comments

Comments

@keegangclarke
Copy link

I keep receiving the following error:
Error in cal$adjust.from(new.from, cal) : attempt to apply non-function

when using bizdays, in the following manner:
bizdays::bizdays(as.Date("2019-01-07"), as.Date("2020-01-03"), cal)
Or simply as:
bizdays::bizdays("2019-01-07", "2020-01-03", cal)

Cal is a user-created calendar using 'create.calendars', which I loaded manually. It functions normally with the other functions of bizdays.
Details of the calendar are as following, in json format:
{ "name": "kospi", "weekdays": [ "saturday", "sunday" ], "holidays": [ "2019-01-01", "2019-01-21", "2019-02-18", "2019-04-19", "2019-05-27", "2019-07-04", "2019-09-02", "2019-11-28", "2019-12-25", "2020-01-01", "2020-01-24", "2020-01-27", "2020-04-30", "2020-05-01", "2020-05-05", "2020-08-30", "2020-10-01", "2020-10-02", "2020-10-09", "2020-12-25", "2020-10-31" ], "adjust.from": "following", "adjust.to": "preceding", "financial": true }

@keegangclarke
Copy link
Author

Same problem with bizdiff:
Error in cal$adjust.from(new.from, cal) : attempt to apply non-function

Example usage:
bizdiff(dates = c("2019-01-07", "2020-01-03"), cal=cal)

@keegangclarke keegangclarke changed the title bizdays function not functioning, returning error instead. bizdays & bizdiff function not functioning, returning error instead. Oct 12, 2022
@wilsonfreitas
Copy link
Owner

Hi @keegangclarke

I created the following reprex and I couldn't reproduce the problems you reported.
Which version are you running? For R and bizdays.

If you run traceback right after the error, the displayed message can help us to find out what is happening.

library(bizdays)
#> 
#> Attaching package: 'bizdays'
#> The following object is masked from 'package:stats':
#> 
#>     offset

cal <- load_calendar("C:/Users/wilso/Dev/R/R-bizdays/test.json")
calendars()
#> Calendars: 
#> actual, Brazil/ANBIMA, Brazil/B3, Brazil/BMF, kospi, weekends
bizdays(as.Date("2019-01-07"), as.Date("2020-01-03"), "kospi")
#> [1] 250
bizdays("2019-01-07", "2020-01-03", "kospi")
#> [1] 250
bizdiff(c("2019-01-07", "2020-01-03"), "kospi")
#> [1] 250

Created on 2022-10-15 with reprex v2.0.2

@wilsonfreitas
Copy link
Owner

Even without the package loading the code worked here.

cal <- bizdays::load_calendar("C:/Users/wilso/Dev/R/R-bizdays/test.json")
bizdays::calendars()
#> Calendars: 
#> kospi
bizdays::bizdays(as.Date("2019-01-07"), as.Date("2020-01-03"), "kospi")
#> [1] 250
bizdays::bizdays("2019-01-07", "2020-01-03", "kospi")
#> [1] 250
bizdays::bizdiff(c("2019-01-07", "2020-01-03"), "kospi")
#> [1] 250

Created on 2022-10-15 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants