You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Data frames code autocomplete, also search for Hmisc labels or other metadata instead of just the variable names? #14242
We have a lot of medical data frames which have standardized variable names, for example variable NL_CM_7_2_9 is "Type Of Tobacco Used", NL_CM_7_2_10 is "Tobacco Use Status" and so on (also see here).
When working on the R scripts for these type of dataframes, it's hard to find the correct variable using the Rstudio auto-complete because of these coded names.
I know we could rename the variables to more meaningful names using dplyr::rename(), but that's not workable because of standardization and for compatibility with scripts/datasets with other sites we are cooperating with.
These variables do already have metadata in the form of labels, added using the Hmisc library. However, using CTRL+space for auto-codecompletion it does not take into account this label metadata.
So my question is, is it possible to have the autocomplete also search in the label metadata when typing?
Error: object 'NL_CM_7_2_1_NL_CM_7_2_9_mapping' not found
I had (incompletely) renamed the NL_CM_7_2_1_NL_CM_7_2_9_mapping variable to df_tobacco_NL_CM_7_2_9_mapping to make it a bit more readable here. The factors and code labels aren't that relevant to the code completion, I kept it in to make the code example close to our irl use-case.
But anyway I've fixed the code in the original post.
Cool, impressive to see how quickly you were able to create a fix for this 👍
But when typing, does it also select the corresponding variable based on either the variable name or when typing (part of) the label description? Or does it just display the label description?
Btw I realize that I didn't include this in the example code, but some descriptions can be longer, like 50 to 150 characters is common, sometimes even longer.
For example take a look at this questionnaire. We have dataset like this, where the variables are named qol_q01, qol_q02 etc and the labels contain "6. Were you limited in doing either your work or other daily activities?" etc.
But when typing, does it also select the corresponding variable based on either the variable name or when typing (part of) the label description? Or does it just display the label description?
The input will match against the whole display string, so you can do something like this:
But accepting the completion will give the variable name as expected.
For example take a look at this questionnaire. We have dataset like this, where the variables are named qol_q01, qol_q02 etc and the labels contain "6. Were you limited in doing either your work or other daily activities?" etc.
We truncate labels larger than 32 characters, but allow you to view the full text on hover.
# An orderless search that looks for the word "color" and # the regular expression "any 4 lowercase letters followed by a _".
sift(starwars, color, "[a-z]{4}_")
#> 4 hair_color#> Type: character Missing: 5 % All same? No #> Peek: blond, unknown, none, auburn, grey, blonde, brown, auburn,…#> #> 5 skin_color#> Type: character Missing: 0 % All same? No #> Peek: white, brown mottle, white, blue, fair, green, yellow, blu…#> #> ✔ There were 2 results for query `(?=.*color)(?=.*[a-z]4_)`.
@DesiQuintans Thanks for the tip, but it sounds like that's a different use-case, for when looking for variables through lots of datasets.
Our reseachers are analyzing datasets and write R scripts to group/sort the data and create charts etc. They usually work with one or two dataset at a time and just want to just quickly lookup the variable name, without having to lookup the labels in the environment pane icon on the right
@BdR76 No, it's the same use case. That's exactly how I work, one or two dataframes at a time for modelling and graphing. It's just that my dataframes are huge, they come from other institutions, and they don't always come with meaningful names or labels, hence searching through as much of that relevant data as possible and not just labels. It's like knowing that one of my 2,000 columns should have "Female" in it, and it turns out it's named something non-obvious like CLSAB with no label.
@DesiQuintans Thanks for the tip, but it sounds like that's a different use-case, for when looking for variables through lots of datasets.
Our reseachers are analyzing datasets and write R scripts to group/sort the data and create charts etc. They usually work with one or two dataset at a time and just want to just quickly lookup the variable name, without having to lookup the labels in the environment pane icon on the right
Activity
kevinushey commentedon Feb 8, 2024
Are you able to share that data, or a separate minimally-reproducible example?
BdR76 commentedon Feb 8, 2024
I had (incompletely) renamed the
NL_CM_7_2_1_NL_CM_7_2_9_mappingvariable todf_tobacco_NL_CM_7_2_9_mappingto make it a bit more readable here. The factors and code labels aren't that relevant to the code completion, I kept it in to make the code example close to our irl use-case.But anyway I've fixed the code in the original post.
BdR76 commentedon Feb 8, 2024
Cool, impressive to see how quickly you were able to create a fix for this 👍
But when typing, does it also select the corresponding variable based on either the variable name or when typing (part of) the label description? Or does it just display the label description?
BdR76 commentedon Feb 8, 2024
Btw I realize that I didn't include this in the example code, but some descriptions can be longer, like 50 to 150 characters is common, sometimes even longer.
For example take a look at this questionnaire. We have dataset like this, where the variables are named
qol_q01,qol_q02etc and the labels contain "6. Were you limited in doing either your work or other daily activities?" etc.kevinushey commentedon Feb 8, 2024
The input will match against the whole display string, so you can do something like this:
But accepting the completion will give the variable name as expected.
We truncate labels larger than 32 characters, but allow you to view the full text on hover.
BdR76 commentedon Feb 8, 2024
(Oops accidentally pressed Close issue)
Sounds perfect, no notes 😀 That's exactly the use-case our statisticians need for the scripts that they're working with.
DesiQuintans commentedon Feb 15, 2024
@BdR76 You might be interested in a package that I wrote for exactly this purpose: https://cran.r-project.org/web/packages/siftr/readme/README.html. It lets me use regex and/or orderless look-around to search for a variable in medical dataframes with potentially millions of rows and thousands of columns. It searches variable names, variable labels, factor levels, and unique values of the data.
BdR76 commentedon Feb 15, 2024
@DesiQuintans Thanks for the tip, but it sounds like that's a different use-case, for when looking for variables through lots of datasets.
Our reseachers are analyzing datasets and write R scripts to group/sort the data and create charts etc. They usually work with one or two dataset at a time and just want to just quickly lookup the variable name, without having to lookup the labels in the environment pane icon on the right
DesiQuintans commentedon Feb 15, 2024
@BdR76 No, it's the same use case. That's exactly how I work, one or two dataframes at a time for modelling and graphing. It's just that my dataframes are huge, they come from other institutions, and they don't always come with meaningful names or labels, hence searching through as much of that relevant data as possible and not just labels. It's like knowing that one of my 2,000 columns should have "Female" in it, and it turns out it's named something non-obvious like CLSAB with no label.
olivroy commentedon Feb 23, 2024
@kevinushey. Wonder if this is intended, but this affects quarto chunk options in yaml and in chunks.
It is cool, but not convinced it is useful. (Please disregard if this was intended) 2024.04.0+470
reproduce by creating a minimal quarto document.
The information is already in the yellow tooltip, so this feels redundant.
fixed by cf7f1df
kevinushey commentedon Feb 23, 2024
Nice catch; we'll want to fix that.
don't include meta for YAML completions (#14242)
ronblum commentedon Mar 13, 2024
Verified in RStudio Desktop 2024.04.0-daily_573 on MacOS 14.4.
Checked the original post:
Checked the additional issue: