diff --git a/vignettes/Setting_default_calendar_in_Rprofile.Rmd b/vignettes/Setting_default_calendar_in_Rprofile.Rmd new file mode 100644 index 0000000..a8b7f70 --- /dev/null +++ b/vignettes/Setting_default_calendar_in_Rprofile.Rmd @@ -0,0 +1,37 @@ +--- +title: "Setting default calendar in .Rprofile" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Setting default calendar in .Rprofile} + %\VignetteEngine{knitr::rmarkdown} + \usepackage[utf8]{inputenc} +--- + + +# Setting default calendar in .Rprofile + +That's the way I use `bizdays`, I set the `default.calendar` in my `.Rprofile`. +Since I am always using `holidaysANBIMA` holidays I create and set the default calendar in my `.Rprofile`. + +```{r} +library(bizdays) +cal <- Calendar(holidays=holidaysANBIMA, name='ANBIMA', weekdays=c('saturday', 'sunday'), dib=252) +bizdays.options$set(default.calendar=cal) +``` + +If you put these 3 lines of code at the end of your `.Rprofile` you don't have to instantiate the calendar every time you use `bizdays`. +You can simply + +```{r} +bizdays(from_dates, to_dates) +``` + +And it works with any of `bizdays` functions: + +- `bizdays`, `bizdayse` +- `bizyears`, `bizyearse` +- `adjust.next`, `adjust.previous` +- `bizseq` +- `is.bizday` +- `offset`, `add.bizdays` diff --git a/vignettes/Using_bizdays.Rmd b/vignettes/Using_bizdays.Rmd new file mode 100644 index 0000000..2a37adb --- /dev/null +++ b/vignettes/Using_bizdays.Rmd @@ -0,0 +1,40 @@ +--- +title: "Using bizdays" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Using bizdays} + %\VignetteEngine{knitr::rmarkdown} + \usepackage[utf8]{inputenc} +--- + +# Using bizdays + +You start by defining a `Calendar` object. + +```{r} +library(bizdays) +cal <- Calendar(holidaysANBIMA, weekdays=c('sunday', 'saturday'), dib=252) +``` + +where `holidays` is a sequence of dates which represents nonworking dates and the second argument, `weekdays`, is a sequence with nonworking weekdays. +`holidays` might be a sequence of strings with ISO formatted dates, `Date` (or `POSIX*`) objects or integers which represent dates in R. +`weekdays` must be a sequence of weekdays in words (lowercase). + +Once you have instantiated a `Calendar` object you simply call `bizdays` function to get the amount of business days between 2 dates (or set of dates). + +```{r} +bizdays(from_dates, to_dates, cal) +``` + +> #### Why define weekdays? +> +> I am frequently asked *Why do I have to define weekdays?* or even *Shouldn't it be `weekenddays` instead?*. +> +> The reason I created `weekdays`: +> I want to provide a way to compute business days accordingly to any definition or satisfying any needs. +> In my world, the financial industry, weekends are nonworking days, but for those who work with events, for example, mondays migth be nonworking days. +> +> `weekdays` defaults to `NULL` because I wanted the `Calendar()` call returned an [Actual](http://en.wikipedia.org/wiki/Day_count_convention#Actual_methods) calendar. +> So calling `Calendar(dib=365, name='Actual/365')` returns an [Actual/365](http://en.wikipedia.org/wiki/Day_count_convention#Actual.2F365_Fixed) calendar. +