Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rmarkdown table style #19

Closed
onesandzeroes opened this issue Mar 19, 2013 · 5 comments
Closed

Add Rmarkdown table style #19

onesandzeroes opened this issue Mar 19, 2013 · 5 comments

Comments

@onesandzeroes
Copy link
Contributor

knitr uses PHP Markdown Extra style tables, which means that pandoc.table() doesn't seem to work well with knitr. Adding a new style to markdown table might make it easier to use pander in a knitr workflow (see, for example Stack Overflow: Programmatically creating Markdown tables in R with KnitR.

PS: I haven't tried to implement the left/right/center alignment yet, but I'm happy to start working on it if needed.

@daroczig
Copy link
Member

Thanks again!
After having a quick view on the PHP Markdown Extra syntax, implementing the alignment would not be much problematic IMHO. As the "simple" style already supports the alignment of the cells, only the separator should be updated for the rmarkdown style - as written on the PHP Markdown Extra homepage:

You can specify alignment for each column by adding colons to separator lines. A colon at the left of the separator line will make the column left-aligned; a colon on the right of the line will make the column right-aligned; colons at both side means the column is center-aligned.

So only the sep.hdr needs some update for the alignment if I am right. Could you tweak that please? If not, I would happily get the time to add that in the next few days.

And as I have never used this syntax: what happens if there is no header or col.names in the object with PHP Markdown Extra/knitr?

For example:

> pandoc.table(matrix(1:4, 2, 2))

---
1 3

2 4
---

@onesandzeroes
Copy link
Contributor Author

I hadn't thought considered when the object has no colnames: the table format seems to require the column names line, even if the column names are blank, so in order to get that matrix to print, you need:

|   |   |
|---|---|
| 1 | 3 |
| 2 | 4 |

I've created a new branch for myself to work on these kinds of issues without adding dozens of commits to the pull request, I'll see what I can put together over the next couple of days. I think I already have the tables working when there are no colnames, but I'll do some further testing and try to get alignment working as well.

@daroczig
Copy link
Member

Awesome, thank you very much!

Please feel free to ping me at any time if I could help you with anything, and also please go ahead with adding dozens of commits to the pull request, IMHO there is no problem with that. Okay, thanks again.

@onesandzeroes
Copy link
Contributor Author

Alright, I now have the table style working with blank column names, and I've written a helper function to align all the columns according to the justify argument. I've only done some basic testing so far, but it's all looking good.

Here's some very quick examples of the results:

RMarkdown input file
Resulting Markdown file
HTML produced by knitr

It should all be in the pull request if you're happy to merge.

@daroczig
Copy link
Member

That's awesome, thanks a lot!
Of course I've merged your commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants