I'm experiencing issue with using texreg in R markdown to produce PDF.
I'm not sure if it's the new OSX or something about my set up. (I'm new to MAC and relatively new to R.)
So far...
I cannot run my old latex files.
I can run the old latex files if I rewrite them in a slightly different syntex (for example take out the \ )
I can run markdown files without texreg.
If I run markdown
with texreg in it, I get an error saying that pandoc cannot convert
the files. Here is the error:
! Misplaced \noalign.
\hline ->\noalign
{\ifnum 0=`}\fi \hrule \#height \arrayrulewidth \futurelet...
l.114 ...sh{}begin\{tabular\}\{l c c c c \} \hline
pandoc: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
In addition: Warning message:
In Ops.factor(left, right) : '<' not meaningful for factors
Execution halted
When I put in texreg function, the closest I have gotten is that it print out the latex code in the pdf.
I'm on OSX EL CAPITAN, newest version of R, MACTEX, PANDOC.
I think knitr, mactex are installed correctly since I can produce pdf from both markdown and latex. Comments?
So may be the problem is pandoc?
I did read a post about some issue with OSX EL CAPITAN and MACTEX but it should be fixed.
Related
I am trying to knit a simple markdown file to a pdf using knitr and R Studio. The chunks all run fine and I have no problems knitting to an HTML document, but get the following error when trying to knit to a pdf:
! LaTeX Error: File `knitr.sty' not found.
I have reinstalled tinytex and made sure that the knitr and rmarkdown packages are up to date. I've looked around and while there are similar issue with other *.sty files, I can't find anything relating to this one.
Thanks in advance for any advice
Solved this: for some reason I had listed several R packages in the 'extra_dependencies' part of the YAML metadata. Once removed it worked.
I have the following line in my R Markdown code chunk
RStudio.Version()$version
when I run the knit on the R Markdown to create a Word document, I get the following error message:
Error in RStudio.Version(): could not find function "RStudio.Version"
When I run this function RStudio.Version() in RStudio console, I get the version and the function runs, but not with knit when I run R Markdown.
Anyone has an advice or solution?
I was able to replicate your issue running RStudio.Version() while knitting. As Phil suggests, rstudioapi::versionInfo() seems the best alternative while knitting.
I am totally new to RStudio and I was working on an RMarkdown document. When I click on Knit PDF, and I keep getting the result like this:
output file: A1-soln-template__2__molly.knit.md
! Package inputenc Error: Unicode char μ (U+3BC)
(inputenc) not set up for use with LaTeX.
See the inputenc package documentation for explanation.
Type H for immediate help.
...
l.142 null hypothesis: Ho:μ
Try running pandoc with --latex-engine=xelatex.
pandoc: Error producing PDF
Error: pandoc document conversion failed with error 43
Execution halted
How can I solve this and get things to work?
Thank you
Try:
install.packages('jsonlite', dependencies=TRUE, repos='http://cran.rstudio.com/')
Also, you might need to install MiKTeX.
The issue here is related to encoding. You are trying to include ASCII characters where they should not be.
In particular, you have typed:
Ho:μ
This needs to be changed to:
$H_0: \mu$
You will need to learn some LaTeX.
I am trying to render a pdf document with the knit pdf button in RStudio, but I keep on getting this error:
! pdfTeX error (font expansion): auto expansion is only possible with scalable
fonts.
\AtBegShi#Output ...ipout \box \AtBeginShipoutBox
\fi \fi
l.167
pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
I know there is a lot be found on the internet regarding error 43, but non of them helped me.
Does anyone know what it means exactly and where I can find the solution? It's peculiar because a few hours ago I had the same error but the rendering went well after adding this in my code:
Sys.setenv(PATH = paste(Sys.getenv("PATH"), "C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64\\", sep=.Platform$path.sep))
But now the error is back
EDIT
when trying a minimal example:
---
title: "test"
output: pdf_document
---
```{r results="asis"}
library(stargazer)
c1 <- c("test1","test1","test2","test2")
c2 <- c(1,2,3,4)
data_object <- as.data.frame(cbind(c1,c2))
names(data_object) <- c("test","test2")
stargazer(data_object,summary=FALSE,rownames=FALSE,type="html")
```
The error it gives is:
!pdfTeX error: pdflatex (file ec-lmr10): Font ec-lmr10 at 600 not found
==> Fatal error occurred, no output PDF file produced!
Trying to make PK font ec-lmr10 at 600 DPI...
Running miktex-makemf.exe...
miktex-makemf: The ec-lmr source file could not be found.
miktex-makepk: The application file ttf2pk.exe could not be found.
pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
This is a different error, but still a 43 one. I checked it, but the font ec-lmr10 file is on the system. Somehow it can't be found.
The problem you have is a font related one. When you knit a PDF, knitr uses LaTeX and you have to know that "fonts" of LaTeX are not like the standard ones.
To solve your problem try to add the latin model font family by loading the package (at the very top):
\usepackage{lmodern}
For more detailed informations about how and where insert this piece of code in your document, have a look here.
This package allows you to have scalable fonts; not all fonts of all (font) packages are to so.
I think, but I might be wrong, because first versions of TeX and LaTeX were designed to work with METAFONT.
Edit
Your code works well for me, it does not produce any error. My idea is that happens because I have a complete Tex live distribution on my Mac (MacTeX). At this point I suppose that the problem relies on some packages that the r packages you use (like stargazer) use and you (we) do not know and won't (unless we analyze the code of course).
At this point my suggestion is to download a complete TeX distribution so you will be sure that any error related to PDF output is no related to the underlying tool that Studio uses to produce such PDFs (say, LaTeX).
You can find a complete LaTeX distribution for Mac and for Windows.
I'm aware that R markdown can produce superscripts:
text^superscript
But is it possible to produce proper subscripts? Or is the only way to do so to cheat and use LaTeX math mode:
$\sf{text_{subscript}}$
The intended final output is HTML.
R Markdown subscript is working normally as it should.
Maybe this is an old post. I'm using RStudio Version 0.99.902 + R Version 3.4 on a Mac.
Subscript: H~2~O is a liquid.
Superscript: 2^10^ is 1024.
Since you mention Pandoc in your comments, maybe it's not cheating to depend on Pandoc's extensions for subscript and superscript. From here, we can create a minimal example Rmd file:
Testing Subscript and Superscript
========================================================
This is an R Markdown document.
Pandoc includes numerous extensions to markdown, and one
of them is *subscript* and *superscript*.
Here's the example from the Pandoc help page
(http://johnmacfarlane.net/pandoc/README.html#superscripts-and-subscripts):
H~2~O is a liquid. 2^10^ is 1024.
For fun, here's an R code block with some code from #Spacedman:
```{r}
list.depth <- function(this, thisdepth = 0) {
# http://stackoverflow.com/a/13433689/1270695
if(!is.list(this)) {
return(thisdepth)
} else {
return(max(unlist(lapply(this, list.depth, thisdepth = thisdepth+1))))
}
}
```
Using Knitr results in an HTML file that renders like this:
That clearly doesn't work. But you can run pandoc on the resulting markdown file (which I've named "Subscripts.md"):
pandoc -o Subscripts.html Subscripts.md -s -S
and you'll get this:
The CSS is different, but perhaps you can call pandoc with a custom CSS argument to use the same CSS used by Knitr.
Subscripts in PDF files also work as expected with that markdown file:
pandoc -o Subscripts.pdf Subscripts.md
Edit
If you want the pandoc output to match the visual appearance of the output when you knit with RStudio, download the CSS file that RStudio uses here and make a reference to that file when you create your HTML file from pandoc. (The following assumes you have kept the name as markdown.css an it is in the same directory as your other files.)
pandoc -o Subscripts.html Subscripts.md -s -S --css=markdown.css
I found that the X~j~ syntax for subscripts works fine in Rmarkdown when knitting in RStudio. However, it does not work if you embed knitting in a shiny app. In my app,
knit2html("Steps.Rmd")
browseURL("Steps.html")
works fine except for the subscripts.
But vanilla HTML subscript syntax will work in your Rmd document for both RStudio and from within a shiny app: X<sub>j</sub> renders as Xj.
For R version 4.0.2 (2020-06-22) this works for me:
Subscript H~2~O~
Superscript R^2^