knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(ggplot2)
library(emphatic)
library(ggplot2)
library(emphatic)
test_df <- head(mtcars, 10)

The methods for selecting columns 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 |---------:|------------:|--------------:| |starts_with() |names of columns start with the given text | starts_with("day")| |ends_with() |names of columns end with the given text |ends_width("2024") | |everything() |all columns (the default behaviour) |everything() | |all_of() | all of the named columns |all_of(c('mpg', 'wt')) | |any_of() | any of the named columns | any_of(c('mpg', 'wt'))| |matches() |regular expression matches against column names |matches("day0\\d+") | |contains() |name contains the given text |contains("value") | |col_number() |the number of column | col_number() == 3 | |all() |select everything |all() | |n() | returns integer specifying number of cols |cols = n() will select the last column |

Select all cols

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

Select cols by index

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

Select cols by name

test_df |>
  hl('skyblue', cols = c('mpg', 'gear'))

Select cols by rowname symbol

test_df |>
  hl('skyblue', cols = c(drat, am))
test_df |>
  hl('skyblue', cols = drat:am)

Select cols using col_number()

test_df |>
  hl('skyblue', cols = col_number() < 4)

Select cols using selectors like tidyselect

test_df |>
  hl('skyblue', cols = contains('a'))
test_df |>
  hl('skyblue', cols = ends_with('t'))
test_df |>
  hl('skyblue', cols = any_of(c('mpg', 'wt', 'age')))


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