Reputation: 21
I am using pandoc.table()
to print out the data frame object, with certain cells highlighted by specifying the parameter, emphasize.strong.cells
. But, the same emphasis characters on row names add some visual complexity. How can I remove these emphasis character on row names.
Upvotes: 1
Views: 710
Reputation: 28632
Thanks for opening an issue for this feature request on GitHub, it should work now:
> panderOptions('table.split.table', Inf)
> pander(head(mtcars), emphasize.rownames = FALSE)
---------------------------------------------------------------------------------------
mpg cyl disp hp drat wt qsec vs am gear carb
------------------- ----- ----- ------ ---- ------ ----- ------ ---- ---- ------ ------
Mazda RX4 21 6 160 110 3.9 2.62 16.46 0 1 4 4
Mazda RX4 Wag 21 6 160 110 3.9 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.32 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.44 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.46 20.22 1 0 3 1
---------------------------------------------------------------------------------------
> panderOptions('table.emphasize.rownames', FALSE)
> pander(head(mtcars))
---------------------------------------------------------------------------------------
mpg cyl disp hp drat wt qsec vs am gear carb
------------------- ----- ----- ------ ---- ------ ----- ------ ---- ---- ------ ------
Mazda RX4 21 6 160 110 3.9 2.62 16.46 0 1 4 4
Mazda RX4 Wag 21 6 160 110 3.9 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.32 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.44 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.46 20.22 1 0 3 1
---------------------------------------------------------------------------------------
Upvotes: 3
Reputation: 1
Here is a fix for printing data frames with pander.
no.emphasis.table <- function(df){
the.row.names <- rownames(df)
add.space <- function(x){
return(paste0(x, ' '))
}
the.row.names.m <- as.vector(sapply(the.row.names, add.space))
rownames(df) <- NULL
df <- cbind(the.row.names.m, df)
colnames(df)[1] <- ''
v.justify <- vector()
v.justify[seq(1, length(df))] <- 'center'
v.justify[1] <- 'left'
set.alignment(v.justify) # Need to explicitly set alignment for first column
return(df)
}
Wrap data frames with this function before printing, e.g.:
pander(no.emphasis.table(df))
Upvotes: 0