Cannot add tikz code snippet in my .Rmd post using blogdown - rstudio

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.

Related

R markdown pandoc document conversion failed with error 1 after updating pandoc from 1.19 to 2.4

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.

Cannot use rmarkdown from RGui

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

How to change lib-path for an RStudio project?

I set R_LIBS_USER to my desired library path in my system environment variables (I already moved my old library to that location). RStudio respects that path when I start the program without opening an existing file. But when I open RStudio by clicking on an .Rproj file, it loads an old lib path and ignores R_LIBS_USER (.libPaths() returns the old path). I searched my %UserProfile% directory and project directory for mentions of the old string. I can't find anything in %UserProfile% directory except in the history_database file, and likewise in the project directory, except for one mention in .Rproj-user\B37F6204\pcs\packages-pane.pper:
{
"installOptions" : {
"installDependencies" : true,
"installFromRepository" : true,
"libraryPath" : "<my-userprofile-path>/R/win-library/3.3"
}
}
This looked promising, but when I changed it, RStudio still ignores it when I open the project.
Clicking on .Rproj files is pretty convenient so I'd like to fix this.
RStudio version is 1.0.136
> sessionInfo()
R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] tools_3.3.3

error log4cxx: No appender could be found for logger (pdflatex). log4cxx: Please initialize the log4cxx system properly

Facing problems with rmarkdown in Rstudio environment.
The following error is being reported:
This is pdfTeX, Version 3.14159265-2.6-1.40.16 (MiKTeX 2.9)
log4cxx: No appender could be found for logger (pdflatex).
log4cxx: Please initialize the log4cxx system properly.
Sorry, but pdflatex did not succeed.
You may want to visit the MiKTeX project page (http://miktex.org), if you
need help.
I saw the same problem being reported by few others but did not find a proposed way to solve.
MikTex 2.9.5721 x64
pandoc 1.15.0.6
sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] devtools_1.8.0
loaded via a namespace (and not attached):
[1] R6_2.1.1 Rcpp_0.12.0 curl_0.9.3 digest_0.6.8 git2r_0.11.0 htmltools_0.2.6 httr_1.0.0 magrittr_1.5
[9] memoise_0.2.1 rmarkdown_0.8 rversions_1.0.2 stringi_0.5-5 stringr_1.0.0 tools_3.1.2 xml2_0.1.1 yaml_2.1.13

RStudio viewer in external browser Issues in Ubuntu14.04

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

Resources