Single space pander table

51 Views Asked by At

How can I make pander print as single space, not double. Curently, if I do:

pander(mtcars[1:5, 1:5])

I get:

--------------------------------------------------------
                    mpg    cyl   disp   hp    drat 
----------------------- ------ ----- ------ ----- ------
     **Mazda RX4**        21     6    160    110   3.9  

   **Mazda RX4 Wag**      21     6    160    110   3.9  

    **Datsun 710**       22.8    4    108    93    3.85 

  **Hornet 4 Drive**     21.4    6    258    110   3.08 

 **Hornet Sportabout**   18.7    8    360    175   3.15 
--------------------------------------------------------

How can I get this instead:

--------------------------------------------------------
                    mpg    cyl   disp   hp    drat 
----------------------- ------ ----- ------ ----- ------
     **Mazda RX4**        21     6    160    110   3.9  
   **Mazda RX4 Wag**      21     6    160    110   3.9  
    **Datsun 710**       22.8    4    108    93    3.85 
  **Hornet 4 Drive**     21.4    6    258    110   3.08 
 **Hornet Sportabout**   18.7    8    360    175   3.15 
--------------------------------------------------------
2

There are 2 best solutions below

0
Tyler Rinker On BEST ANSWER

From @daroczig via: https://github.com/Rapporter/pander/issues/327

pander::pander(mtcars[1:5, 1:5], style = 'simple')

## --------------------------------------------------------
##                     mpg    cyl   disp   hp    drat 
## ----------------------- ------ ----- ------ ----- ------
##      **Mazda RX4**        21     6    160    110   3.9  
##    **Mazda RX4 Wag**      21     6    160    110   3.9  
##     **Datsun 710**       22.8    4    108    93    3.85 
##   **Hornet 4 Drive**     21.4    6    258    110   3.08 
##  **Hornet Sportabout**   18.7    8    360    175   3.15 
## --------------------------------------------------------
0
Tyler Rinker On

Here's a hacky way:

single_print <- function(x, ...){
    out <- capture.output(pander(x, ...))
    cat(out[out != ''], sep = '\n')
}

single_print(mtcars[1:5, 1:5])

## --------------------------------------------------------
##         &nbsp;           mpg    cyl   disp   hp    drat 
## ----------------------- ------ ----- ------ ----- ------
##      **Mazda RX4**        21     6    160    110   3.9  
##    **Mazda RX4 Wag**      21     6    160    110   3.9  
##     **Datsun 710**       22.8    4    108    93    3.85 
##   **Hornet 4 Drive**     21.4    6    258    110   3.08 
##  **Hornet Sportabout**   18.7    8    360    175   3.15 
## --------------------------------------------------------

I have asked this to be a feature here: https://github.com/Rapporter/pander/issues/327