---
title: "Specifying Rows"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Specifying Rows}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(ggplot2)
library(emphatic)
```

```{r setup}
library(ggplot2)
library(emphatic)
```

```{r}
test_df <- head(mtcars, 10)
```



The methods for selecting rows works similar to `tidyselect` used by 
dplyr.   This is a bespoke implementation of these selections, and may not work
exactly the same:


| selector | description | example
|---------:|------------:|--------------:|
|`all()` |all rows | `all()`|
|`starts_with()` |rownames start with the given text | `starts_with("day")`|
|`ends_with()` |rownames end with the given text  |`ends_width("2024")` |
|`everything()` |all rows (the default behaviour)  |`everything()` |
|`all_of()` | **all** of the specified rownames |`all_of(c('mpg', 'wt'))` |
|`any_of()` | **any** of the specified rownames | `any_of(c('mpg', 'wt'))`|
|`matches()` |regular expression matches against rownames |`matches("day0\\d+")` |
|`contains()` |rowname contains the given text |`contains("value")` |
|`row_number()` |the number of row | `row_number() == 3` |
|`all()` |select everything |`all()` |
|`n()` | returns integer specifying number of rows |`rows = c(n(), n() / 2)` will select last row and half-way|


Select all rows
------------------------------------------------------------------------------

```{r}
test_df |>
  hl('skyblue')
```

```{r}
test_df |>
  hl('skyblue', rows = NULL)
```

```{r}
test_df |>
  hl('skyblue', rows = all())
```


Select rows by index
------------------------------------------------------------------------------

```{r}
test_df |>
  hl('skyblue', rows = 2:5)
```

Select rows by name
------------------------------------------------------------------------------

```{r}
test_df |>
  hl('skyblue', rows = c('Mazda RX4', 'Datsun 710'))
```

Select rows by rowname symbol
------------------------------------------------------------------------------

```{r}
test_df |>
  hl('skyblue', rows = Valiant)
```


Select rows by expression
------------------------------------------------------------------------------

```{r}
test_df |>
  hl('skyblue', rows = mpg > 22)
```

Select rows using `n()` and `row_number()`
------------------------------------------------------------------------------

```{r}
test_df |>
  hl('skyblue', rows = row_number() > n()/2)
```

Select rows using selectors like `tidyselect`
------------------------------------------------------------------------------

```{r}
test_df |>
  hl('skyblue', rows = contains('hornet'))
```

```{r}
test_df |>
  hl('skyblue', rows = starts_with('m'))
```


```{r}
test_df |>
  hl('skyblue', rows = any_of(c('Valiant', 'Herbie', 'Datsun 710')))
```

