insightsengineering / rlistings

Value formatting and ASCII rendering infrastructure for tables and listings.
https://insightsengineering.github.io/rlistings/
24 stars 5 forks source link

Fix bug in `add_listing_col` when using a function and specifying a format #179

Closed edelarua closed 11 months ago

edelarua commented 12 months ago

When adding a column with add_listing_col using a function to create the new column from pre-existing columns, the supplied name is not used and if the format argument is also specified then an error occurs.

Example:

lsting <- as_listing(
    mtcars[1:5, ],
    key_cols = c("gear", "carb"),
    disp_cols = "qsec"
  ) %>%
    add_listing_col(
      "kpg",
      function(df) df$mpg * 1.60934,
      format = "xx.xx"
    )

Output:

sorting incoming data by key columns
Error in attr(obj, "format") <- value : 
  attempt to set an attribute on NULL
Called from: `obj_format<-`(`*tmp*`, value = "xx.xx")
shajoezhu commented 12 months ago

nice catch Em!