positron icon indicating copy to clipboard operation
positron copied to clipboard

Data Explorer: Display column labels for R columns

Open jmcphers opened this issue 1 year ago β€’ 12 comments

You can add a label attribute to columns in an R data frame. This is helpful to provide a description of the column that's more verbose than the name you use in code.

df_test <- data.frame(x = 1)
attr(df_test$x, "label") <- "x label"
View(df_test)

In RStudio, this name gets displayed in column header:

image

But you can't see it in Positron.

image

(originally requested via https://github.com/posit-dev/positron-beta/discussions/113#discussioncomment-9147231)

jmcphers avatar May 02 '24 15:05 jmcphers

Putting this into the future, we've prioritized column-type over custom labels. I would like to see if others are interested in this. Perhaps we can mockup using labels as an alternative OR how labels + type would work.

One thought we had internally was we could probably replace the column type with the custom variable label from the dataframe.

jthomasmock avatar May 06 '24 15:05 jthomasmock

I think type is important, universal, and should be always present.

I sort of think of labels as an anti-pattern, personally, encouraging the maintenance of non-human readable variable names.

jsonbecker avatar Jun 28 '24 16:06 jsonbecker

I think type is important, universal, and should be always present.

I sort of think of labels as an anti-pattern, personally, encouraging the maintenance of non-human readable variable names.

Yes, understood! There's also some inconsistency with them round-tripping across various dataframe implementations.

jthomasmock avatar Jun 28 '24 18:06 jthomasmock

If I see right, currently types are shown in the left column. So there would be additionally place for labels, similar to RStudio, and then you have both types and labels.

strengejacke avatar Jun 29 '24 13:06 strengejacke

Also mentioned here: https://github.com/posit-dev/positron/discussions/3773#discussion-6886419 and here https://github.com/posit-dev/positron/discussions/3686#discussion-6872791

dfalbel avatar Jul 01 '24 17:07 dfalbel

SDTM datasets (pharma) typically come with labels (xpt and sas7bdat) - RStudio displaying the labels in those cases is very helpful (typically read in with haven).

andersone1 avatar Jul 29 '24 17:07 andersone1

+1 for column labels! πŸ•ΊπŸΌ

ddsjoberg avatar Jul 29 '24 23:07 ddsjoberg

Supporting custom labels will likely come at the cost of type, and we'll almost certainly need to expand the height/width of the Column Label to support the extra text at an appropriate size for accessibility.

Option 1: Convert type into a symbol

image

Option 2: Drop type completely

image

jthomasmock avatar Jul 30 '24 14:07 jthomasmock

What if labels were shown upon hovering the column name? We could add a symbol like eg β“˜ somewhere to make it discoverable.

dfalbel avatar Jul 30 '24 14:07 dfalbel

I would love to see both type and custom labels! They are each an important part of my day-to-day data analysis and communication workflow.

Of the two options presented I lean towards Option 1 with both type and custom labels. My ideal setup though, would be an Option 3 with taller Column Labels that could allow type to have its own line rather than being displayed as a symbol. In Option 3 users would also have the option to toggle custom labels on or off in global settings. 😊

spcanelon avatar Aug 02 '24 00:08 spcanelon

A blog post here about why these are important: https://www.pipinghotdata.com/posts/2022-09-13-the-case-for-variable-labels-in-r/

jmcphers avatar Aug 15 '24 16:08 jmcphers

A blog post here about why these are important: https://www.pipinghotdata.com/posts/2022-09-13-the-case-for-variable-labels-in-r/

Thanks for mentioning my blog post! I think I make a stronger case for it in my posit conf talk "Context is King." 😊 The TL; DR is that being able to view column labels is an empowering and effective way for users to get up to speed with the nuances of what variables actually mean.

shannonpileggi avatar Aug 15 '24 20:08 shannonpileggi

Requested again in https://github.com/posit-dev/positron/issues/5288.

jmcphers avatar Nov 06 '24 22:11 jmcphers

It would be straightforward to add a column_schema.label field in the backend protocol, if we can agree on how to display this in the front end?

wesm avatar Mar 21 '25 20:03 wesm

Brought up again in https://github.com/posit-dev/positron/discussions/9173

juliasilge avatar Aug 26 '25 12:08 juliasilge

I'm going to take a crack at this, will post PR for discussion

wesm avatar Aug 26 '25 13:08 wesm

Take a look at the video in #9179, feedback welcome! With these changes, the label is shown if present, otherwise the type, and I added a tooltip that shows type and label (or just type if there is no label). To get both the type and label displaying would be some CSS engineering, and may have diminishing returns if it crowds an already rather tight UI

wesm avatar Aug 26 '25 16:08 wesm

The PR merged shows the column labels in tooltips which is helpful. If we want to have them visible at a glance, then we'll have to do some more design / CSS engineering work, so I would suggest we resolve this issue and relegate future design work to a follow up issue. Feedback welcome!

wesm avatar Sep 12 '25 18:09 wesm

Verified Fixed

Positron Version(s) : 2025.10.0-95
OS Version          : OSX

Test scenario(s)

Label visible in tooltip.

Link(s) to TestRail test cases run or created:

testlabauto avatar Sep 16 '25 13:09 testlabauto