Reputation: 822
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
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
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
Reputation: 986
I'd replace Benjamin's   with NULL but otherwise agree:
temp <- iris[1:4,]; names(temp) <- rep(NULL, ncol(temp)); temp[1:4,]
pandoc.table(temp)
Upvotes: 1
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