Skip to content

t1flex removes column headers for extra.col in version 1.5.1 #142

@nabihlme

Description

@nabihlme

t1flex removes column headers for extra.col in version 1.5.1. I wrote a function to add back column headers below:

table1 = function(...) {
        tbl = table1::table1(...)
        obj = attr(tbl, "obj", exact=TRUE)
        tbl = table1::t1flex(tbl) %>% 
                flextable::theme_zebra() %>% 
                flextable::set_table_properties(layout="autofit")
        # change less than symbol to html encoded version
        for(i in 1:length(tbl$body$content$data)) {
                tmp = tbl$body$content$data[[i]]
                tmp$txt = gsub("&lt;", "<", tmp$txt)
                tbl$body$content$data[[i]] = tmp
        }
        # Add back column headers
        for(idx in which(names(obj$headings) == "")) {
                tbl$header$dataset[1,idx+1]          = obj$headings[idx]
                tbl$header$content$data[[idx+1]]$txt = obj$headings[idx]
        }
        tbl
}

Might be related to:
https://github.com/benjaminrich/table1/blob/6de79c2ea5b9a96f469fbc77906cc690475ce8ea/R/table1.R#L1265C1-L1265C55
Might need a check if names(headings) == "", something like:
headings <- ifelse(names(headings)=="", headings, names(headings))

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