gt icon indicating copy to clipboard operation
gt copied to clipboard

Feature Request: `str_replace()`, `str_replace_all()` like renaming within `cols_label()` to apply across as many columns as applicable

Open ScoobyQ opened this issue 4 years ago • 1 comments

I would like to see cols_label support multi-column renames using pattern matching and specified replacement strings for matches much like str_replace, str_replace_all.

If I had columns such as: c1_mean_2019-20, c1_mean_2020-21, I would like to be able to replace c1_mean_ with '', leaving 2019-20, 2020-21. This needs to happen IN the gt object.

Something like:

cols_label( contains('c1_mean_') = str_replace(contains('c1_mean_'),'c1_mean_', '') )

Looking at cols_label this functionality does not appear to exist.

ScoobyQ avatar Dec 21 '20 03:12 ScoobyQ

This is a good idea! Could work in the form of

cols_label(contains("...") = ~ fn(.))

So that any string manipulation functions would work. We'd have to also ensure that helpers such as md(), html(), etc., continue to work in this form

cols_label(contains("...") = md(~ fn(.)))

and this

cols_label(contains("...") = ~ md(fn(.)))

rich-iannone avatar Apr 27 '21 18:04 rich-iannone

Fixed by #1158.

rich-iannone avatar Dec 05 '22 22:12 rich-iannone