Skip to content

Changing values strips formats from row #995

@Melkiades

Description

@Melkiades
library(rtables)
lyt <- basic_table() %>%
  split_cols_by("Species") %>%
  analyze("Sepal.Length", afun = function(x) {
    list(
      "mean (sd)" = rcell(c(mean(x), sd(x)), format = "xx.xx (xx.xx)"),
      "range" = rcell(diff(range(x)), format = "xx.xxx")
    )
  })
lyt
#> A Pre-data Table Layout
#> 
#> Column-Split Structure:
#> Species (lvls) 
#> 
#> Row-Split Structure:
#> Sepal.Length (** analysis **)

tbl <- build_table(lyt, iris)
tbl
#>               setosa      versicolor     virginica 
#> ———————————————————————————————————————————————————
#> mean (sd)   5.01 (0.35)   5.94 (0.52)   6.59 (0.64)
#> range          1.500         2.100         3.000
tbl[1, 2] <- rcell(1)
tbl
#>                      setosa            versicolor          virginica        
#> ————————————————————————————————————————————————————————————————————————————
#> mean (sd)   5.006, 0.352489687213451       1        6.588, 0.635879593274432
#> range                1.500               2.100               3.000
tbl[2, 1] <- rcell(1)
tbl
#>                      setosa            versicolor          virginica        
#> ————————————————————————————————————————————————————————————————————————————
#> mean (sd)   5.006, 0.352489687213451       1        6.588, 0.635879593274432
#> range                  1                  2.1                  3

Created on 2025-02-12 with reprex v2.1.1

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions