I am trying to print xtable in using knitr in word document as follows:
library(knitr)
library(xtable)
p1<-xtable(head(iris), include.rownames=FALSE, floating=FALSE)
print(p1)
I get this error, any ideas:
latex table generated in R 3.2.2 by xtable 1.7-4 package % Mon Oct 26 11:17:22 2015
I don't think you can do this with the standard word_document that comes with rmarkdown. xtable only produces output in HTML and LaTeX formats. To render a word document, your table has to be prepared in markdown format (so far as I know).
Some alternative options are to use knitr::kable or the pixiedust package.
If you're comfortable downloading things from GitHub, you may also use devtools::install_github("gforge/Grmd") and then replace output:word_document with output: Grmd::docx_document. Then using print.xtable with type = 'html' will render to an HTML document that can be opened as a docx.
Related
I was reading here that $$ is deprecated in LaTeX and replaced with \[ and \]. It seems the opposite when I use R Markdown in R Studio though.
If I wrap an equation in $$ it will display block style, live preview, in my R Markdown (in R Studio). If I use \[ and \] it will still knitr fine, but it won't showup R Studio live preview. See below.
---
title: "Untitled"
author: "March 2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
\[x = R + F\]
$$x = R + E$$
The linked Q&A is correct. $$ is deprecated for LaTeX. However, you are not writing LaTeX but Rmarkdown, which is processed by pandoc. In the pandoc manual we find:
TeX math will be printed in all output formats. How it is rendered depends on the output format:
LaTeX
It will appear verbatim surrounded by \(...\) (for inline math) or \[...\] (for display math).
So you can use $$...$$ in Rmarkdown documents and still have the correct output when converting to PDF via LaTeX. The other form works due to another pandoc extension. If you need cross-references for equations, you should use bookdown, though.
I'm doing a LaTex document using RStudio in Windows 7 by using knitr. I've have some problems such as:
When I use xtable() for these data frames , I just can get the code for Latex, is it possible to get directly the Latex format of tables in my pdf?
I found R markdown/knitr useful tool to document my work and generate summary document.
I work with .Rmd (R markdown) files in RStudio.
It seems that knitr provide appropriate functionality to generate .odt (Open Document Text) and .tex (LaTeX) documents from .Rmd.
However, R studio allows to choose .docx, .html and .pdf formats only.
I would like to avoid MS Word format since I prefer open standards and working under Linux.
Is it possible to add .odt and .tex options to Rstudio menu?
It doesn't seem possible to output odt directly in RStudio, but you can always use knitr::knit to produce a markdown document and pandoc to produce the odt:
library(knitr)
knit("myDoc.Rmd")
system("pandoc myDoc.md -o myDoc.odt")
You may have to adjust the pandoc options and adapt the template to get a nice looking result.
As for latex, you can keep the tex sources when compiling to pdf with the following option in your yaml front matter:
---
output:
pdf_document:
keep_tex: true
---
I am trying to use a Beamer theme that requires \usepackage[no-math]{fontspec} with a KnitR document. Here is a minimal example test.Rnw:
\documentclass[handout]{beamer}
\usepackage[no-math]{fontspec}
\begin{document}
\maketitle
<<include=FALSE>>=
options(tikzDefaultEngine='xetex')
#
\begin{frame}{test}
\begin{figure}[htbp]
<<echo=FALSE, dev="tikz">>=
plot(1:100)
#
\end{figure}
\end{frame}
\end{document}
When I Knit the doucument I get:
Error in getMetricsFromLatex(TeXMetrics) :
TeX was unable to calculate metrics for the following string
or character:
m
Common reasons for failure include:
* The string contains a character which is special to LaTeX unless
escaped properly, such as % or $.
* The string makes use of LaTeX commands provided by a package and
the tikzDevice was not told to load the package.
This is an issue specifically related to the no-math option with fontspec along with dev="tikz". If I remove either of these, the document compiles fine. Any suggestions on how to get this to work? The entire purpose of using a tikz device is to allow the format of my graphics to match up with my theme that requires I am trying to use a Beamer theme that requires \usepackage[no-math]{fontspec}. Thanks!
By using xtable and knitr, I add a table to my RMD document and export to PDF file.
```{r, results='asis'}
library(xtable)
xtable(matrixtable)
````
It looks great except there is a line
% latex table generated in R 3.1.0 by xtable 1.7-3 package % Wed Jun 25 13:34:57 2014
How can I remove this line. I tried to set message=FALSE but it doesn't work.
The inclusion of the comment in the final table is defined by the comment argument to print.xtable
the default value for this is getOption('xtable.comment',TRUE).
so, if you set
options(xtable.comment = FALSE)
then for any future tables this comment will not produced.
You can put in directly in the print statement like so:
xtb=xtable(...)
print(xtb, comment=FALSE)