Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature requests: Simple manipulations of variable labels #153

Closed
sda030 opened this issue Nov 19, 2023 · 5 comments · Fixed by #158
Closed

Feature requests: Simple manipulations of variable labels #153

sda030 opened this issue Nov 19, 2023 · 5 comments · Fixed by #158

Comments

@sda030
Copy link

sda030 commented Nov 19, 2023

Hi Joseph, I was wondering whether something like the following would be something to include in the package? It is relatively easy to do it in a script for an intermediate R user, but I have newbie colleagues who find it a bit overwhelming/complicated to set up a loop across variable labels, etc. And cleaning variable labels are very important, as you might know, in the social sciences for effective science outreach.

Imagine this generalized solution to the common problem of wanting to generally process many variables' labels.
labelled::process_var_labels(data, ..., .f = ~stringr::str_replace_all(.x, pattern = "sad socks", replacement = "Happy socks")) # returns dataframe/tibble.
The elipses would preferably take tidyselect-notation.
The stringr-function can of course be replaced by the user to something like str_trim, etc.
Not very advanced to implement and maintain, the tidyselect you already have in the package. To ensure that stringr/stringi works as efficiently as possible, it would probably be best to first extract all the labels into a named vector, and then process them.

Let me know if you are too busy and I could try something.

P.S. Function should ignore NULL-labels, yet return the correct labels to each variable..

@larmarange
Copy link
Owner

Dear @sda030

Yes such a function could be considered to be added in the package.

I'm currently traveling for work reasons, but I would be happy to look at a PR.

Best regards

@larmarange
Copy link
Owner

Hi. Are you still interested in such feature?

What about two functions update_variable_labels_with() and update_value_labels_with() allowing to apply a function to variable / value labels. Following dplyr::rename_with(), we could consider a .cols argument to apply it only to certain columns.

These two functions will be applied only to data.frames.

@sda030
Copy link
Author

sda030 commented Mar 19, 2024

That sounds excellent Joseph! I attempted one myself but was unsatisfied with lack of vectorization. Then looked into Rust but never got around to a solution. I'm sure you can do something better than me.

larmarange added a commit that referenced this issue Mar 19, 2024
…s_with()`

allowing to update variable/value labels with a custom function

fix #153
@larmarange
Copy link
Owner

you may have a look and test #158

@sda030
Copy link
Author

sda030 commented Mar 19, 2024

Works well! This will assist my colleagues so much.

larmarange added a commit that referenced this issue Mar 28, 2024
* new functions `update_variable_labels_with()` and `update_value_labels_with()`

allowing to update variable/value labels with a custom function

fix #153

* pkgdown

* typo

* typo

* update github actions

* additional tests

* lint

* wordlist
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 a pull request may close this issue.

2 participants