AndriusZ
AndriusZ

Reputation: 822

Removing column names in pandoc table - r markdown

Is it possible to remove (not to show) column names in pandoc tables?
If I use pander (or pandoc.table) function it prints column names automatically.

> pander(iris[1:4, ])

-------------------------------------------------------------------
 Sepal.Length   Sepal.Width   Petal.Length   Petal.Width   Species 
-------------- ------------- -------------- ------------- ---------
 5.1            3.5           1.4            0.2       setosa  

 4.9             3            1.4            0.2       setosa  

 4.7            3.2           1.3            0.2       setosa  

 4.6            3.1           1.5            0.2       setosa  
-------------------------------------------------------------------

Expected output should be:

-------------------------------------------------------------------
                                         
-------------- ------------- -------------- ------------- ---------
 5.1            3.5           1.4            0.2       setosa  

 4.9             3            1.4            0.2       setosa  

 4.7            3.2           1.3            0.2       setosa  

 4.6            3.1           1.5            0.2       setosa  
-------------------------------------------------------------------

Upvotes: 1

Views: 1690

Answers (4)

o_v
o_v

Reputation: 142

setting column names to NULL like so names(dt) <- NULL actually gives an error. In my case

Error in alloc.col(newx) : Internal error: length of names (0) is not length of dt (2)

using a data.table with 2 columns.

Instead, I'd go with

names(dt) <- rep(" ", ncol(dt)) pander(dt)

Upvotes: 0

daroczig
daroczig

Reputation: 28632

I'd fix this outside of pander by simply removing the column headers:

> df <- iris[1:4, ]
> names(df) <- NULL
> pander(df)

--- --- --- --- ------
5.1 3.5 1.4 0.2 setosa

4.9  3  1.4 0.2 setosa

4.7 3.2 1.3 0.2 setosa

4.6 3.1 1.5 0.2 setosa
--- --- --- --- ------

Upvotes: 4

greengrass62
greengrass62

Reputation: 986

I'd replace Benjamin's &nbsp with NULL but otherwise agree:

temp <- iris[1:4,]; names(temp) <- rep(NULL, ncol(temp)); temp[1:4,] 
pandoc.table(temp)

Upvotes: 1

Andrew Chisholm
Andrew Chisholm

Reputation: 6567

Would this suffice?

pandoc.table({temp <- iris; names(temp) <- rep(" ", ncol(temp)); temp[1:4,]})

to yield.

----------------------

--- --- --- --- ------
5.1 3.5 1.4 0.2 setosa
4.9  3  1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
----------------------

Upvotes: 1

Related Questions