---
title: "Introduction to schtools"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Introduction to schtools}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
schtools::set_knitr_opts()
knitr::opts_chunk$set(
  collapse = TRUE,
  echo = TRUE,
  comment = "#>"
)
```

```{r setup}
library(schtools)
```

## Parsing mothur output files

### Phylip-formatted distance file as a tibble
 
```{r read_dist}
dist_filepath <- system.file("extdata",
                             "sample.final.thetayc.0.03.lt.ave.dist",
                             package = "schtools")
dist_tbl <- read_dist(dist_filepath)
head(dist_tbl)
```

## Miscellaneous helpers

When writing scientific papers with R Markdown, we often find ourselves 
using the same knitr chunk options and miscellaneous helper functions.
To use our favorite options like `eval=TRUE`, `echo=FALSE`, and others,
run `set_knitr_opts()` in the first chunk of your R Markdown document:


````markdown
`r ''````{r, include = FALSE}
set_knitr_opts()
```
````

This also sets the inline hook to our custom `inline_hook()` function, which
automatically formats numbers in a human-readable way and inserts an Oxford
comma into lists when needed.

### Who doesn't love an Oxford comma?

When writing with R Markdown, you may wish to insert a list or vector 
inline and correctly format it with an Oxford comma. 
`inline_hook()` uses `paste_oxford_list()` to help you do just that!

```{r oxford}
animals <- c('cats', 'dogs', 'fish')
```

Insert the string as inline code with `` `r ` ``:

> `` `r "\u0060r animals\u0060"` `` are the most common pets.

Rendered output:

> `r paste_oxford_list(animals)` are the most common pets.


### Human-readable numbers

`inline_hook()` uses `format_numbers()` under the hood to automatically format
numbers to a human-readable format, rather than display in scientific notation.

> The numbers `` `r "\u0060r c(1e-04, 1e-05, 1e-06)\u0060"` `` are very precise,
> while `` `r "\u0060r c(1e04, 1e05, 1e06)\u0060"` `` are very large.

Rendered output:

> The numbers `r inline_hook(c(1e-04, 1e-05, 1e-06))` are very precise.
> while `r inline_hook(c(1e04, 1e05, 1e06))` are very large.

