harrelfe / Hmisc

Harrell Miscellaneous
Other
205 stars 81 forks source link

Option to remove unnecessary formatting with print of the summary methods #125

Open tamas-ferenci opened 4 years ago

tamas-ferenci commented 4 years ago

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:

(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...?