/
README.Rmd
79 lines (56 loc) · 2.84 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# HolidayAPI
<!-- badges: start -->
<!-- badges: end -->
The goal of HolidayAPI package is making worldwide holidays / bank days accessible to the R community. The package is an API wrapper of the [Holiday API](https://holidayapi.com/) offering easy access to all official endpoints. You can see details of the API documentation and limitations at [https://holidayapi.com/docs](https://holidayapi.com/docs). Be aware that you need a key of the API, which you can get for free at [https://holidayapi.com/signup](https://holidayapi.com/signup).
## Installation
You can install the released version of HolidayAPI from [GitHub](https://github.com/) with the following commands in `R`:
``` r
# install.packages("devtools")
devtools::install_github("matbmeijer/HolidayAPI")
```
## Example
To work, you will need to save your API key - the package automatically loads the key for every function once you have saved the key:
``` r
library(HolidayAPI)
save_key("____YOUR_API_KEY_HERE____")
```
This is a basic example showing how to obtain holiday data for Spain for `r as.numeric(format(Sys.Date(), "%Y"))-1`. Piping is also possible, as well as converting holidays to a `data.frame`:
```{r example}
library(HolidayAPI)
last_year<-as.numeric(format(Sys.Date(), "%Y"))-1
holidays_df<-get_holidays(country = "ES", year = last_year)
summary(holidays_df)
class(holidays_df)
holidays_df<-holidays_df %>% as.data.frame()
class(holidays_df)
knitr::kable(head(holidays_df, 5), row.names = FALSE, caption = "Example of spanish holidays", format = "markdown")
```
Some useful functions are the ` r get_countries()` and the ` r get_langugages()` functions, with the prior returning updated information about all the supported countries and regions (the API offers both national and regional holiday information) and the latter returning updated information about the different supported languages (on deafault the API returns english).
```{r example2}
countries_df<-get_countries()
summary(countries_df)
class(countries_df)
countries_df<-countries_df %>% as.data.frame()
class(countries_df)
knitr::kable(head(countries_df, 5), row.names = FALSE, caption = "Example of available countries & subdivisions", format = "markdown")
languages_df<-get_languages()
summary(languages_df)
class(languages_df)
languages_df<-languages_df %>% as.data.frame()
class(languages_df)
knitr::kable(head(languages_df, 5), row.names = FALSE, caption = "Example of available languages", format = "markdown")
```
Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md).
By participating in this project you agree to abide by its terms.