Skip to content

make cutData generic#460

Draft
jack-davison wants to merge 5 commits intomainfrom
genericCutData
Draft

make cutData generic#460
jack-davison wants to merge 5 commits intomainfrom
genericCutData

Conversation

@jack-davison
Copy link
Collaborator

This reformats cutData() into a generic function, and exports a load of vector methods as well as the data.frame method.

Methods are provided for POSIXCt, Date, Double, Integer, Character and Factor vectors, as well as data.frames (and anything that inherits the class, like tibbles).

Being a generic, this allows cutData() to be extended by other packages, if desired, and to be used more flexibly by users. For example:

mydata |>
  dplyr::mutate(
    month = cutData(date, "month"),
    no2_splits = cutData(no2),
    wd = cutData(wd, "wd")
  )

You could also achieve something funky like:

openairmaps::polar_data |>
  dplyr::mutate(
    no2 = cutData(no2),
    .by = site
  ) |>
  tidyr::drop_na(no2) |>
  ggplot(aes(x = no2, y = nox)) +
  geom_boxplot() +
  facet_wrap(vars(site), scales = "free_x")
image

@jack-davison jack-davison marked this pull request as draft December 19, 2025 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant