Skip to content

Column names as back up for variable labels in tables? #74

@courtiol

Description

@courtiol

Dear @gdemin,
I find that {expss} is a nice package to create tables, even for those handling non labelled variables or values!
When dealing with multiple variables, in the absence of variable labels, I was wondering if you could implement column names as a back up could improve the display.
Here is an example comparing the default behaviour and the application of a small work-around implementing the idea:

library(expss)
#> 
#> Use 'expss_output_rnotebook()' to display tables inside R Notebooks.
#>  To return to the console output, use 'expss_output_default()'.
expss_output_rnotebook()
iris_small <- head(iris, n = 2)
calculate(iris_small, fre(list(Sepal.Length, Sepal.Width)))
 Count   Valid percent   Percent   Responses, %   Cumulative responses, % 
 4.9  1 50 50 50 50
 5.1  1 50 50 50 100
 \#Total  2 100 100 100
 <NA>  0 0
 3  1 50 50 50 50
 3.5  1 50 50 50 100
 \#Total  2 100 100 100
 <NA>  0 0
for (i in seq_len(ncol(iris_small))) {
  attr(iris_small[[i]], "label") <- colnames(iris_small)[i]
  class(iris_small[[i]]) <- c("labelled")
}

calculate(iris_small, fre(list(Sepal.Length, Sepal.Width)))
 Count   Valid percent   Percent   Responses, %   Cumulative responses, % 
 Sepal.Length 
   4.9  1 50 50 50 50
   5.1  1 50 50 50 100
   \#Total  2 100 100 100
   <NA>  0 0
 Sepal.Width 
   3  1 50 50 50 50
   3.5  1 50 50 50 100
   \#Total  2 100 100 100
   <NA>  0 0

Created on 2020-11-17 by the reprex package (v0.3.0)

I think that doing this internally, would save the trouble of people not handling labels to do so and the documented way seems fastidious for many columns, but perhaps I missed something:

library(expss)
expss_output_rnotebook()
iris_small <- head(iris, n = 2)

iris_small <- modify(iris_small, {var_lab(Sepal.Length) = "Sepal.Length"
                                  var_lab(Sepal.Width) = "Sepal.Width"})

calculate(iris_small, fre(list(Sepal.Length, Sepal.Width)))
 Count   Valid percent   Percent   Responses, %   Cumulative responses, % 
 Sepal.Length 
   4.9  1 50 50 50 50
   5.1  1 50 50 50 100
   \#Total  2 100 100 100
   <NA>  0 0
 Sepal.Width 
   3  1 50 50 50 50
   3.5  1 50 50 50 100
   \#Total  2 100 100 100
   <NA>  0 0

Created on 2020-11-17 by the reprex package (v0.3.0)

Thanks for considering this feature request

Alex

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions