knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(ggplot2)
library(emphatic)
library(ggplot2)
library(emphatic)
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

test_df |>
  hl('skyblue')
test_df |>
  hl('skyblue', rows = NULL)
test_df |>
  hl('skyblue', rows = all())

Select rows by index

test_df |>
  hl('skyblue', rows = 2:5)

Select rows by name

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

Select rows by rowname symbol

test_df |>
  hl('skyblue', rows = Valiant)

Select rows by expression

test_df |>
  hl('skyblue', rows = mpg > 22)

Select rows using n() and row_number()

test_df |>
  hl('skyblue', rows = row_number() > n()/2)

Select rows using selectors like tidyselect

test_df |>
  hl('skyblue', rows = contains('hornet'))
test_df |>
  hl('skyblue', rows = starts_with('m'))
test_df |>
  hl('skyblue', rows = any_of(c('Valiant', 'Herbie', 'Datsun 710')))


coolbutuseless/emphatic documentation built on Dec. 27, 2024, 1:18 a.m.