Skip to content

Commit

Permalink
Added vignettes
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonfreitas committed Jan 30, 2015
1 parent 2d1f181 commit 24eaf0c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
37 changes: 37 additions & 0 deletions vignettes/Setting_default_calendar_in_Rprofile.Rmd
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`
40 changes: 40 additions & 0 deletions vignettes/Using_bizdays.Rmd
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.

0 comments on commit 24eaf0c

Please sign in to comment.