I would like to generate a PDF via RMarkdown from the RGui.
I am able to knit the file via RStudio but it fails every time via RGui.
This is "essai.r" file that contains the render command.
library(rmarkdown)
library(knitr)
Sys.setenv(RSTUDIO_PANDOC="C:/Program Files (x86)/Pandoc")
rmarkdown::render("essai.Rmd", output_format = "pdf_document", clean = FALSE)
This is "essai.rmd"
---
title: "test"
output: pdf_document
---
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r}
summary(cars)
```
You can also embed plots, for example:
```{r, echo=FALSE}
plot(cars)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
And this is my configuration:
> sessionInfo()
R version 3.3.0 (2016-05-03)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows Server 2012 R2 x64 (build 9600)
locale:
[1] LC_COLLATE=French_Switzerland.1252 LC_CTYPE=French_Switzerland.1252 LC_MONETARY=French_Switzerland.1252
[4] LC_NUMERIC=C LC_TIME=French_Switzerland.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_1.12.3 rmarkdown_0.9.5
loaded via a namespace (and not attached):
[1] magrittr_1.5 formatR_1.4 tools_3.3.0 htmltools_0.3.6 yaml_2.1.13 Rcpp_0.11.2
[7] stringi_1.0-1 stringr_1.0.0 digest_0.6.13 evaluate_0.8
And this is the error that appears every time:
> source("essai.r")
"C:/Program Files (x86)/Pandoc/pandoc" +RTS -K512m -RTS essai.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output essai.pdf --template "C:\PROGRA~1\R\R-33~1.0\library\RMARKD~1\rmd\latex\DEFAUL~2.TEX" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"
pandoc.exe: Cannot decode byte '\xbd': Data.Text.Internal.Encoding.Fusion.streamUtf8: Invalid UTF-8 stream
Erreur : pandoc document conversion failed with error 1
I made sure that both files are saved as UTF-8. And also I tried to change my system locale.
What am I missing?
Regards
Related
I have just started using blogdown and I have created a project by using template Hugo-Xmin. In RStudio, when creating the project in blogdown, it created some predefined posts, I am editing this one:
/content/post/2015-07-23-r-rmarkdown.Rmd
Adding a tikz image
Following this question and the bookdown documentation on engines, I modified the afore-mentioned file by adding this snippet:
This is a tikz picture:
```{r, echo=FALSE, engine='tikz', out.width='90%', fig.ext=if (knitr:::is_latex_output()) 'pdf' else 'png', fig.cap='Some caption.'}
\begin{tikzpicture}[scale=.7]
\draw [fill=gray!30,very thick] (0,-1) rectangle (5,1);
\draw [very thick] (5, 0) -- (13,0);
\node [below] at (2,-1) {\large Hello};
\node [below, align=center] at (0,-1) {\large Two\\ lines};
\end{tikzpicture}
```
Failed to process the post
As soon as I save (since I have the serve on), but also when using blogdown::build_site(), I get this:
> blogdown::serve_site()
Rendering content/post/2015-07-23-r-rmarkdown.Rmd
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018/W32TeX) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
Quitting from lines 49-55 (2015-07-23-r-rmarkdown.Rmd)
Error: Failed to compile .\tikz53878cd6189.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips.
Execution halted
Error in render_page(f) :
Failed to render 'content/post/2015-07-23-r-rmarkdown.Rmd'
Troubleshooting
I checked my engines and saw that tikz is actually among them:
> names(knitr::knit_engines$get())
[1] "awk" "bash" "coffee" "gawk" "groovy" "haskell" "lein" "mysql"
[9] "node" "octave" "perl" "psql" "Rscript" "ruby" "sas" "scala"
[17] "sed" "sh" "stata" "zsh" "highlight" "Rcpp" "tikz" "dot"
[25] "c" "fortran" "fortran95" "asy" "cat" "asis" "stan" "block"
[33] "block2" "js" "css" "sql" "go" "python" "julia" "theorem"
[41] "lemma" "corollary" "proposition" "conjecture" "definition" "example" "exercise" "proof"
[49] "remark" "solution"
The documentation said that some engines are shipped in bookdown and not knitr, but I can see tikz is there! So I have the engine, but still I cannot use it. What am I doing wrong?
More info
A log file /content/post/texput.log is generated and reports this info on the failure:
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018/W32TeX) (preloaded format=pdflatex 2019.1.11) 25 FEB 2019 07:54
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
**.\tikz3cac449b1071.tex
! Emergency stop.
<*> .\tikz3cac449b1071.tex
*** (job aborted, file error in nonstop mode)
Here is how much of TeX's memory you used:
3 strings out of 492616
115 string characters out of 6132768
56950 words of memory out of 5000000
4017 multiletter control sequences out of 15000+600000
3640 words of font info for 14 fonts, out of 8000000 for 9000
1141 hyphenation exceptions out of 8191
0i,0n,0p,1b,6s stack positions out of 5000i,500n,10000p,200000b,80000s
! ==> Fatal error occurred, no output PDF file produced!
If I check knitr:
> xfun::session_info('knitr')
R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200), RStudio 1.1.463
Locale:
LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
LC_MONETARY=English_United States.1252 LC_NUMERIC=C
LC_TIME=English_United States.1252
Package version:
evaluate_0.13 glue_1.3.0 graphics_3.5.2 grDevices_3.5.2 highr_0.7 knitr_1.21.13
magrittr_1.5 markdown_0.9 methods_3.5.2 mime_0.6 stats_3.5.2 stringi_1.3.1
stringr_1.4.0 tools_3.5.2 utils_3.5.2 xfun_0.5 yaml_2.2.0
This turns out to be an issue in knitr which I just fixed on Github (I'm not sure if it is a bug of pdflatex). You may try
remotes::install_github('yihui/knitr')
Note that you will need to install two additional R packages, magick and pdftools, if they haven't been installed yet.
I recently installed pandoc 2.4 on Windows and the conversion failed with error 1 occurs for all knitting. I can't knit html, word, and pdf.
The error says
output file: template.knitmd
pandoc.exe: template.utf8.md: openBinaryFile: does not exist (No such file or directory)
Error: pandoc document conversion failed with error 1
Execusion halted
This happens to even the raw basic template rmd file.
I am using a closed network without internet connection and limited writing permission. Previously I was able to knit rmd files located in documents folder generating outputs in same location.
The sessionInfo() says
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: windows >=8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_collate=english_united states.1252 lc_ctype=english_united states.1252 lc_monetary=english_united states.1252
[4] LC_Numeric=C LC_TIME=english_united states.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] flextable_0.4.5 officer_0.3.2 knitr_1.20 rmarkdown_1.10
loaded via a namespace (and not attached):
[1] Rcpp_1.0.0 digest_0.6.18 rprojroot_1.3-2 R6_2.3.0 backports_1.1.2 magrittr_1.5 evaluate_0.12
[8]zip_1.0.0 stringi_1.2.4 gdtools_0.1.7 uuid_0.1-2 xml2_1.2.0 tools_3.5.1 stringr_1.3.1
[15] yaml_2.2.0 compiler_3.5.1 base64enc_0.1-3 htmltools_0.3.6
Any advice will be highly appreciated. (Or even ways how to change the settings back to old pandoc version without deleting the version 2.4.)
I have had this issue as well. Mapping the network drive where my R project was stored by following the instructions here solved the issue for me.
I'm trying to enable LaTeX for Anki flashcards. I have MikTex installed and, upon attempting to view cards with LaTex formatting, I get the following error:
Définissez Problème à l’exécution de latex.
Fichier généré : C:\Users\user\AppData\Local\Temp\anki_temp\tmp.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (MiKTeX 2.9.6800 64-bit)
entering extended mode
(tmp.tex
LaTeX2e <2018-04-01> patch level 5
("C:\Program Files\MiKTeX 2.9\tex\latex\base\article.cls"
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
("C:\Program Files\MiKTeX 2.9\tex\latex\base\size12.clo"))
("C:\Program Files\MiKTeX 2.9\tex\latex\base\fontenc.sty"
("C:\Program Files\MiKTeX 2.9\tex\latex\base\t1enc.def"))
("C:\Program Files\MiKTeX 2.9\tex\latex\base\inputenc.sty"
! LaTeX Error: File `utf8x.def' not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: def)
Enter file name:
! Emergency stop.
<read *>
l.165 \endinput
No pages of output.
I've already disabled automatic package installation/prompting of the user to install unknown packages in MikTex, to no avail.
What can I do to fix this so that Anki displays LaTeX cards?
I was experiencing similar problems and none of the in-depth ansers seemed to help me , but I just stumbled upon a solution that works for me.
As long as I only use \( to begin LaTeX Code and \) to end it, everything works well on my two Windows computers, as well as my Android device.
example:
\(\sum_{k = 1}^{\infty}\frac{1}{k}\)
instead of
\begin{math}\sum_{k = 1}^{\infty}\frac{1}{k}\end{math}
Hope this helps other noobs as well.
Fixed the problem by following the tutorial at
http://www.eighthourlunch.com/content/anki-setting-latex-windows-7
One issue which was unclear in the tutorial was installation of the xml/sgml typesetting package. It is called passivetex and can be viewed at https://miktex.org/packages/passivetex
Use the filter menu in the packages tab of the miktex console to explicitly search for passivetex . Once installed, I updated the file name database (Tasks -> Update filename database) and Anki started working correctly.
I've got a particular bug in my environment such that I cannot consistently knit Rmarkdown files to HTML, Word documents, or PDFs. The ability to knit varies across by file type.
HTML - Sometimes it knits
Word document - Sometimes it knits
PDF - Never knits. Always throws the same error
The error is:
Segmentation fault/access violation in generated code
Error: pandoc document conversion failed with error 1
Up until a week ago, I was able to knit to all three file types in the same environment so this is a relatively recent bug. The high-level specs of my environment are:
OS: Windows 10
R: 3.4.3
RStudio: 1.1.419
knitr: 1.19
rmarkdown: 1.8
pandoc: 1.19.2.1
MiKTeX : 2.9
As an example of the inconsistency in the ability to knit, I crated a new .Rmd file in RStudio which creates the familiar standard template of summary(cars) and plot(pressure) etc. I didn't change anything about it. I was able to knit it successfully to HTML once, Word .docx once, and then I tried to knit to PDF and got the error above. I then went back and attempted to knit to both HTML and Word and received the error even though nothing changed from the original knit. This is just an example of the type of behavior. Different documents behave differently.
To troubleshoot, I've reinstalled R and RStudio (I believe pandoc comes up with the RStudio install so I've effectively reinstalled pandoc too). The reinstallation did not help. I've tried clearing the Knitr Cache. That didn't work either. I've browsed SO and the internet and found a few similar errors related to the Glasgow-Haskell compiler, but I have no idea what that is and if it's the source of the issue.
Here is an example of the .Rmd file that throws the error:
---
title: "Untitled"
author: "Vypa"
date: "February 8, 2018"
output:
html_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
And here is the full console error:
Segmentation fault/access violation in generated code
Error: pandoc document conversion failed with error 1
In addition: Warning message:
running command '"C:/Users/Vypa/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS tst.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output tst.html --smart --email-obfuscation none --self-contained --standalone --section-divs --template "C:\Users\Vypa\Documents\R\R-3.4.3\library\rmarkdown\rmd\h\default.html" --no-highlight --variable highlightjs=1 --variable "theme:bootstrap" --include-in-header "C:\Users\Vypa\AppData\Local\Temp\RtmpI9Gxsx\rmarkdown-str5db029544a23.html" --mathjax --variable "mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"' had status 1
Execution halted
Any help or thoughts would be appreciated.
Encountered the same problem after a recent install of R & RStudio on Win10. Pandoc problem showed up on edit and knitr of previously err free .rmd file.
Resolved after installing latest preview ver of RStudio at
https://www.rstudio.com/products/rstudio/download/preview/
Updating pandoc fixed this for me.
https://pandoc.org/installing.html
Thanks #EuGENE. Adding here as an answer for clarity.
I have one Ubuntu14.04 laptops,
when I run below with RStudio Viewer, it work fines.
> library(dygraphs)
> dygraph(ldeaths, main = "All", group = "lung-deaths")
After I set below options to run in external browser,
options("viewer"=NULL)
dygraph(ldeaths, main = "All", group = "lung-deaths")
The browser will open files with below URL but nothing show:
http://localhost:18186/session/viewhtmla4c45554fcb/index.html
If I do the same thing in R console
library(dygraphs)
dygraph(ldeaths, main = "All", group = "lung-deaths")
it work fine and will open with URL with file:///tmp/RtmpE7nROm/viewhtmlf371b65fc2c/index.html
Questions1: Why Rstudio will open "http://localhost:18186..." instead of "file://....."?
Questions2: What commands in Rstudio to revert the display show in Viewer again? Currently I have to quit Rstudio and restart to get show in Viewer again.
PS: I doesn't see this issue in another Linux Labtops, not sure what configuration will causing this, hope someone can help to answer!
Below are sessionInfo() show in RStudio
sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.3 LTS
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=zh_TW.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=zh_TW.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=zh_TW.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=zh_TW.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dygraphs_0.4.6
loaded via a namespace (and not attached):
[1] htmlwidgets_0.5 zoo_1.7-12 magrittr_1.5 htmltools_0.2.6 tools_3.2.2 xts_0.9-7
[7] rstudioapi_0.3.1 yaml_2.1.13 grid_3.2.2 jsonlite_0.9.16 digest_0.6.8 lattice_0.20-33