---
title: "Alphordering Numbers"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Alphordering Numbers}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
set.seed(1)
library(magrittr)
poorly_ordered <- expand.grid(98:103, 9:11) %>%
  apply(1, function(x) paste0("patient", x[1], "-day", x[2], ".png")) %>%
  sample(size = length(.))
```

## Numbers don't comply with alphabetical order

`poorly_ordered` is a vector of file names of images of patient samples from different days.

```{r poorly-ordered}
poorly_ordered
```

How do we get this vector into order? Well, alphabetical order doesn't work:

```{r sort-attempt}
sort(poorly_ordered)
```

Patient 100 comes before patient 99. This is because 1 comes before 9 in alphabetical order.


## Alphordering numbers

It's possible to _alphord_ the numbers by prefixing them with zeroes:

```{r alphordering}
strex::str_alphord_nums(poorly_ordered)
```

Having done this, the alphabetical order is the one we want:

```{r good-sort}
sort(strex::str_alphord_nums(poorly_ordered))
```