---
title: "csodata quick start guide"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{csodata quick start guide}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

#### Introduction

This guide provides a basic overview of the use of the csodata package for new users. Install (if necessary) and load the package:

```{r setup}
# # Install or update the package:
# install.packages("csodata")

library(csodata)
```

#### Table of Contents

A list of all the table available on the cso StatBank can be downloaded with `cso_get_toc`. You can search through the title field using `cso_search_toc`. (A "Loaded cached toc" or "Loaded cached data" message indicates that the data was retrieved from the cache, instead of being downloaded again.)
```{r}
toc <- cso_get_toc()
head(toc)
```

#### Downloading Data

To download a dataset, use `cso_get_data` and include a table code from the table of contents.

```{r}
tbl1 <- cso_get_data("PEA19")
```

Metadata can be also downloaded or displayed to console:

```{r}
meta1 <- cso_get_meta("CDP06")
cso_disp_meta("CDP06")
```

#### Geographic Data

Geographic vector data in ESRI shapefile format can be downloaded for use in mapping. This is a map of county councils and other local authorities in Ireland,
there are many other maps available.

```{r}
shp <- cso_get_geo("County Councils")
```

This data can be plotted using the `leaflet` package. Here we plot the outline of each region.

```{r, fig.width = 5, fig.height=6, eval= !is.null(shp)}
# install.packages("leaflet")
library(leaflet)


leaflet(shp) %>% 
  addTiles() %>% 
  addPolygons()


```

The data which has been cached locally can be manually cleared once we are done with it.

```{r}
cso_clear_cache()
```
