[R] Tables, knitr markdown

Gergely Daróczi gergely at snowl.net
Tue Feb 23 00:44:23 CET 2016


On Mon, Feb 22, 2016 at 3:36 PM, Santosh <santosh2005 at gmail.com> wrote:
> Thanks, Gergely.. I wonder if it allows to insert lines etc as sent in
> previous email.... which might need some additional preprocessing..

AFAIK that's not possible, as pandoc's markdown has no markup to add
horizontal/vertical lines in tables as per
http://pandoc.org/README.html#tables
But a possible workaround is to generate HTML and load that in Word/OpenOffice.

>
> Best,
> Santosh
>
>
> On Mon, Feb 22, 2016 at 3:27 PM, Gergely Daróczi <gergely at snowl.net> wrote:
>>
>> On Mon, Feb 22, 2016 at 1:55 PM, Duncan Murdoch
>> <murdoch.duncan at gmail.com> wrote:
>> >
>> > On 22/02/2016 3:46 PM, Santosh wrote:
>> >>
>> >> Just figured out..
>> >>
>> >> as.data.frame(as.matrix(<tabular_object>),stringsAsFactors=F)
>> >>
>> >> could work! :)
>> >
>> >
>> > Why do you want to produce Markdown output?  the tables package
>> > (lowercase t!) can produce output in either LaTeX or HTML.  Just tell knitr
>> > to leave the output alone, e.g. for PDF output
>> >
>> > ```{r results="asis"}
>> > require(tables)
>> > tab <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)*
>> >          (Sepal.Length + Sepal.Width)*(mean + sd), data=iris )
>> > latex(tab)
>> > ```
>> >
>> > or for HTML output
>> >
>> > ```{r results="asis"}
>> > require(tables)
>> > tab <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)*
>> > (Sepal.Length + Sepal.Width)*(mean + sd), data=iris )
>> > html(tab)
>> > ```
>>
>>
>> In case of you would rather generate markdown instead of HTML/LaTeX to
>> be independent from the resulting output document format, you can give
>> a try to the "pander" package, which can transform quite many R object
>> types into markdown, eg:
>>
>> #> library(tables)
>> #> tab <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)*
>> #+          (Sepal.Length + Sepal.Width)*(mean + sd), data=iris )
>> #> pander::pander(tab)
>>
>> ------------------------------------------------------------
>>      \        \    Sepal.Length\    \    Sepal.Width\    \
>>   Species     n         mean        sd       mean        sd
>> ------------ ---- ---------------- ---- --------------- ----
>>   *setosa*    50        5.01       0.35      3.43       0.38
>>
>> *versicolor*  50        5.94       0.52      2.77       0.31
>>
>> *virginica*   50        6.59       0.64      2.97       0.32
>>
>>    *All*     150        5.84       0.83      3.06       0.44
>> ------------------------------------------------------------
>>
>> Please find more details at
>> http://rapporter.github.io/pander/#generic-pander-method, or the
>> knitr+pander vignette at
>> https://cran.rstudio.com/web/packages/pander/vignettes/knitr.html
>>
>> Best,
>> Gergely
>>
>>
>> >
>> >
>> >
>> >
>> > Duncan Murdoch
>> >
>> >
>> >>
>> >>
>> >> On Mon, Feb 22, 2016 at 12:17 PM, Santosh <santosh2005 at gmail.com>
>> >> wrote:
>> >>
>> >>> Dear Rxperts..
>> >>> I am able to generate tables using Tables R package..
>> >>> However, when I have been unsuccessful in using kable (from knitr
>> >>> package)
>> >>> to generate the table in R markdown script..
>> >>>
>> >>> It's because the output generated by "tabular" in Tables package is of
>> >>> class "tabular". The kable function in knitr package accepts
>> >>> data.frame.
>> >>>
>> >>> Is there a way to convert the tabular class objects into data.frame
>> >>>   objects?
>> >>>
>> >>> Or is there a way that kable can accept "tabular" class object?
>> >>>
>> >>>
>> >>> Thanks so much..
>> >>> Santosh
>> >>>
>> >>
>> >>         [[alternative HTML version deleted]]
>> >>
>> >> ______________________________________________
>> >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> >> https://stat.ethz.ch/mailman/listinfo/r-help
>> >> PLEASE do read the posting guide
>> >> http://www.R-project.org/posting-guide.html
>> >> and provide commented, minimal, self-contained, reproducible code.
>> >>
>> >
>> > ______________________________________________
>> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>
>



More information about the R-help mailing list