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

Correcting the rename dialog? #9265

Open
rdstern opened this issue Nov 18, 2024 · 9 comments
Open

Correcting the rename dialog? #9265

rdstern opened this issue Nov 18, 2024 · 9 comments
Assignees
Labels

Comments

@rdstern
Copy link
Collaborator

rdstern commented Nov 18, 2024

t2_subset.xlsx

Here is a dataset where many variables start with X.

I would like to delete the X. from the names using thre Rename 3rd option by a function.

If I do it really simply, namely replace X. by empty, it gives and error in dplyr. I think that is because of the default using regex. So I tried replacing X\\. and it no longer gives an error, but also doesn't replace.

Help please and we should also write this up. Can @N-thony or @lilyclements help?

@lilyclements
Copy link
Contributor

lilyclements commented Nov 18, 2024

Thanks for this @rdstern. The issue is that the code is looking for the wrong columns because you're using "Starts with" not "Matches".

tidyselect::starts_with() does not support regular expressions, so it is currently selecting columns which literally start with "^X\."
We need to call the ^X\\. for a different parameter in our R code, however.
To use regular expressions to match column names this way, we can use tidyselect::matches() instead, which supports regex.

So all you need to do is change from the "Starts with" option to "Matches":

image

(I've put the replacement as NEW as otherwise there's an issue that we already have a column called date)

@rdstern
Copy link
Collaborator Author

rdstern commented Nov 18, 2024

@lilyclements great. I also misunderstood the error that I got, because I assumed it was because of the dot and regex. It was because of the names being duplicated.

You see I wanted it to be simple. Just delete Xdot from the start of each name - So I was really happy that I can easily replace Xdot by NEW using starts with and no trouble!

I still need to write this up properly in the help, and possibly edit the dialog a bit if some options assume regex by default and others do not.

@N-thony
Copy link
Collaborator

N-thony commented Nov 19, 2024

I noticed also this error when you in Edit option, click on Abbreviate and then back again to Edit, and click Ok, you get the following error.
image

@lilyclements
Copy link
Contributor

@N-thony thanks for reporting. That error is that the X\\. from the ucrInput is not being read into the tidyselect::starts_with() function. Should be an easy fix when it's taken up :)

@N-thony
Copy link
Collaborator

N-thony commented Nov 19, 2024

@N-thony thanks for reporting. That error is that the X\\. from the ucrInput is not being read into the tidyselect::starts_with() function. Should be an easy fix when it's taken up :)

Yes, that is correct, @derekagorhom or @Fidel365 can easily fix this.

@rdstern rdstern changed the title Changing names with a dot in them, via the rename dialog? Correcting the rename dialog? Nov 20, 2024
@rdstern rdstern added the bug label Nov 20, 2024
@rdstern
Copy link
Collaborator Author

rdstern commented Nov 20, 2024

WE are often hitting an error after using the Rename with button and then using with the Single or the Multiple Buttons afterward. It still tries to process the rename with option. It is always resolved by pressing Reset.
Could you imporve the code, so it only processes the option from the open button.

t1_100.zip

Here is an example to try:

Importing the file I want to delete the superflous dates (9 columns), or trhe rename with fails, because names that then not unique. Nasty message though!

Then change Date to Day followed by Rename With, on Edit > Starts with X. to nothing works fine.

But the X, forst and then changfinf Date to Day afterwards, gives an error.

@N-thony
Copy link
Collaborator

N-thony commented Nov 21, 2024

@Fidel365 any plan on this?

@Fidel365
Copy link
Contributor

@N-thony on it

@rachelkg
Copy link
Contributor

@N-thony, @Fidel365 and @lilyclements

While we are talking about the Renaming Dialog I have a question.

Why is the edit option only available on the data frame tab. It seems like it would be useful on the Selected Variables tab too, could it be added? All the other options seem to be the same.

2024-11-25_14-59-14

2024-11-25_14-59-02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants