Hmisc
Hmisc copied to clipboard
Option to remove unnecessary formatting with print of the summary methods
I usually create the typical ''Table 1'' (basic patient demographics, potentially with some stratification like gender) with the summary
methods of Hmisc
(eg. summaryM
, summary.formula
). Their print
method works nicely for character display, but if I further pass it (two typical examples: to a csv file, or to knitr::kable
for a markdown file), it adds unnecessary formatting:
- It may break lines in the column titles
- It adds spaces before the absolute frequency for a categorical variables within the parenthesis
(There are possibly more similar examples, but these are the ones I found so for.)
I usually remove them manually:
temp[ 1, ] <- gsub( "\n", "", temp[ 1, ], fixed = TRUE )
for( i in 2:nrow( temp ) ) {
for( j in 1:ncol( temp ) ) {
temp[ i, j ] <- gsub( "\\s+(?=[^()]*\\))", "", trimws( temp[ i, j ] ), perl = TRUE )
}
}
but it is everything but elegant.
Would it be possible to add an option to print
which would make it not adding such formatting...?