Reputation: 1076
I am trying to plot a table in R but it just print the text in a dummy format, not sure how to fix it.
My Code:
tex2=TeX('
\\begin{table}[]
\\begin{tabular}{|l|l|}
\\hline
a&b \\\\ \\hline
c & d \\\\ \\hline
\\end{tabular}
\\end{table}
')
plot(tex2, cex=1)
tex2 is equivalent of
\begin{table}[]
\begin{tabular}{|l|l|}
\hline
a&b \\ \hline
c&d \\ \hline
\end{tabular}
\end{table}
as suggested by https://cran.r-project.org/web/packages/latex2exp/vignettes/using-latex2exp.html
Upvotes: 0
Views: 338
Reputation: 84519
To view a LaTeX snippet in the RStudio viewer pane, with the possibility to export it as an image, you need the texPreview
package.
library(texPreview)
tex <- '
\\begin{table}[]
\\begin{tabular}{|l|l|}
\\hline
a & b \\\\ \\hline
c & d \\\\ \\hline
\\end{tabular}
\\end{table}
'
tex_preview(tex, imgFormat = "svg")
When I tried it the first time, it didn't work. I got this error:
Error in magick_image_readpath(enc2native(path), density, depth, strip) : rsession: not authorized `/tmp/RtmpKZqeBQ/tex_tempDoc.pdf' @ error/constitute.c/ReadImage/412
I'm using Ubuntu. I had to make a change in the file /etc/ImageMagick-6/policy.xml; namely I replaced the line
<policy domain="coder" rights="none" pattern="PDF" />
with
<policy domain="coder" rights="read | write" pattern="PDF" />
Upvotes: 2