-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d1f181
commit 24eaf0c
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||