tidyverts / tsibble

Tidy Temporal Data Frames and Tools
https://tsibble.tidyverts.org
GNU General Public License v3.0
528 stars 50 forks source link

Feature request: Add a tidyselect function to select everything except index and index_by columns #314

Open travis-leith opened 2 months ago

travis-leith commented 2 months ago

It would be useful to have a function that selects all data columns (excluding index and any columns created by index_by). For example, I am converting some tibble based code into tsibble based code. My current code looks like this

data |>
mutate(across(-dtm, ~ log(.x / lag(.x))))

But I have to know what the index column is called. Would be nice to be able to write generic code that takes a tsibble and knows what to do with it without knowing what the index is called. It's been a while since I used xts but I seem to recall that the index is not a normal column in xts and so such generic code is natural.

The following does not work

data |>
mutate(across(everything(), ~ log(.x / lag(.x))))

because everything() includes the index column.

What I am proposing is one or both of the following options

data |>
mutate(across(-index_column(), ~ log(.x / lag(.x))))
data |>
mutate(across(data_columns(), ~ log(.x / lag(.x))))

with perhaps more thought given to the actual names of these functions.