---
title: "working with buoy data"
author: "Scott Chamberlain"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{working with buoy data}
  %\VignetteEngine{knitr::rmarkdown}
  \usepackage[utf8]{inputenc}
---

```{r, echo = FALSE, warning = FALSE, message = FALSE}
knitr::opts_chunk$set(
  collapse  =  TRUE,
  comment  =  "#>",
  purl  =  FALSE,
  eval  =  FALSE
)
```

This vignette covers NOAA buoy data from the National Buoy Data Center. The
main function to get data is `buoy`, while `buoys` can be used to
get the buoy IDs and web pages for each buoy.


```{r}
library('rnoaa')
```

## Find out what buoys are available in a dataset

```{r}
res <- buoys(dataset = "cwind")
```

Inspect the buoy ids, and the urls for them

```{r}
head(res)
```

Or browse them on the web

```{r eval=FALSE}
browseURL(res[1, 2])
```

## Get buoy data

With `buoy` you can get data for a particular dataset, buoy id, year, and datatype. 

Get data for a buoy

> if no year or datatype specified, we get the first file

```{r cache=TRUE}
buoy(dataset = 'cwind', buoyid = 46085)
```

Including year

```{r cache=TRUE}
buoy(dataset = 'cwind', buoyid = 41001, year = 1999)
```

Including year and datatype

```{r cache=TRUE}
buoy(dataset = 'cwind', buoyid = 45005, year = 2008, datatype = "c")
```

Including just datatype

```{r cache=TRUE}
buoy(dataset = 'cwind', buoyid = 45005, datatype = "c")
```
