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

Add a "labels with" button to the rename dialog? #9280

Open
rdstern opened this issue Nov 27, 2024 · 3 comments
Open

Add a "labels with" button to the rename dialog? #9280

rdstern opened this issue Nov 27, 2024 · 3 comments
Assignees

Comments

@rdstern
Copy link
Collaborator

rdstern commented Nov 27, 2024

This is maybe "the icing on the cake" but might be an easy puzzle for @lilyclements first, and then for someone else to implement?

We have started using the rename with option on the variable names. Very powerful!

Could we also apply this the get tidier variable labels? Here is a discussion in stack-overflow.

I suggest, to avoid clutter, we might make it a separate (4th) button at the top. And maybe just the edit option?

Might it be easy? It shows the power of R, currently, but also how messy it is as a language perhaps, and hence our challenge to bring these tasks within reach of non-R-whizzes!

And to encourage good statistical practice by making these tasks easy!

Introductory Survey (1).xlsx

Here is a dataset, downloaded from Moodle with just 14 questions. The names are long, so I've copied them into the labels. Then I made short names. But the labels are a bit messy. I suppose I could edit them elsewhere, but why not in R-Instat - and in context.

Maybe not as I have another option and I'm releived it has worked. I copied the names and then used Paste New, which worked fine. Then I used Prepare > Column: Text > Find Replace - and the Replace option see here:

image

This worked fine. But I wonder why we don't have the Starts With, Contains, etc commands here?

@lilyclements
Copy link
Contributor

lilyclements commented Nov 27, 2024

  1. Could it be an option to have not just Data Frames in the receiver, but the option to choose the Column Metadata on this dialog as a way to edit the labels?
  2. Agreed we could have the starts with, ends with, matches, and contains in the Find/Replace dialog.
  3. To have an option to switch labels with variable names, or vice versa, the copy + paste option works currently quite nicely. We could have a checkbox though to just do that copy + paste for you?

@lilyclements
Copy link
Contributor

lilyclements commented Nov 27, 2024

@rdstern to add to my comment on point 3:

If you want to rename your labels in your metadata with the names of it

# For ALL columns:
col_names <- data_book$get_column_names("Responses")
purrr::map(.x = col_names,
           .f = ~data_book$append_to_variables_metadata(data_name="Responses",
                                                        col_names=.x,
                                                        property="label",
                                                        new_val=gsub("=", "", .x)))

# for specific columns (e.g., column 1 and 2):
col_names=c("Response.number","Which.is.the.name.of.your.duty.station.")
purrr::map(.x = col_names,
           .f = ~data_book$append_to_variables_metadata(data_name="Responses",
                                                        col_names=.x,
                                                        property="label",
                                                        new_val=gsub("=", "", .x)))

# If you wanted to change the label to something else (not the Name) through a dialog for specific columns:
col_names=c("Response.number","Which.is.the.name.of.your.duty.station.")
new_label=c("This is a new label", "Hello Roger")
# add a different new label
purrr::map2(.x = col_names,
            .y = new_label,
           .f = ~data_book$append_to_variables_metadata(data_name="Responses",
                                       col_names=.x,
                                       property="label",
                                       new_val=.y))

If you want to rename all columns in your data with the metadata label in R-Instat:

responses_metadata <- data_book$get_variables_metadata("Responses")

data_book$rename_column_in_data(data_name="Responses",
                                type="rename_with",
                                .fn= ~ responses_metadata$label,
                                .cols = responses_metadata$Name)

@rdstern
Copy link
Collaborator Author

rdstern commented Nov 27, 2024

@lilyclements and @N-thony I am really liking the improvements coming here. I may be exaggerating the importance, but I think we can really be comprehensive here, and that is making a difficult job easier.

@lilyclements suggested a very simple addition to be able to rename with for the variable labels:

image

Here is the dialog now.

a) Add a third radio button to this option, just saying Labels.
b) @lilyclements can you confirm that with the Labels option we omit the first options. So the whole box can have the label "Edit"?
c) So, in the box, the first label could be Command and then the rest is the same?
d) Then it needs you to give the code, so it edits the Variable label?

e) Now an addition for @N-thony . Lily, I think you said that Matches is the only command that uses regex? Could the group box be deeper, for both the data frame and the labels options, with the regex keyboard labelled here Regex Keyboard. This is disabled except for the Matches option, when it is enabled!

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

No branches or pull requests

3 participants