R markdown knit error with pandoc error 83 - r-markdown

I want to knit but I failed. I spend many time for solve it, but I couldn't. I can't knit even basic Rmd code like...
---
title: "Untitled"
date: "2022-09-20"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
error said
output file: knit.knit.md
"C:/Users/곽민승/Desktop/Install/RStudio/bin/quarto/bin/tools/pandoc" +RTS -K512m -RTS knit.knit.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output knit.html --lua-filter "C:\Users\곽민승\AppData\Local\R\win-library\4.2\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\곽민승\AppData\Local\R\win-library\4.2\rmarkdown\rmarkdown\lua\latex-div.lua" --self-contained --variable bs3=TRUE --section-divs --template "C:\Users\곽민승\AppData\Local\R\win-library\4.2\rmarkdown\rmd\h\default.html" --no-highlight --variable highlightjs=1 --variable theme=bootstrap --mathjax --variable "mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --include-in-header "C:\Users\곽민승\AppData\Local\Temp\RtmpolhuTr\rmarkdown-str11e44397877.html"
Error running filter C:\Users\곽민승\AppData\Local\R\win-library\4.2\rmarkdown\rmarkdown\lua\pagebreak.lua:
cannot open C:\Users\곽민승\AppData\Local\R\win-library\4.2\rmarkdown\rmarkdown\lua\pagebreak.lua: Invalid argument
**error: pandoc document conversion failed with error 83**
곽민승 is my name, and r markdown packages are installed,
pandoc verson is 2.18,
saving is UTF-8
I know there are lots of solution in google, but I was in hurry because homework due date is tomorrow. PLEASE help me.

This is likely the result of a bug in pandoc's Lua subsystem before 2.19: filenames were assumed to be UTF-8 encoded instead using the local encoding on Windows. The program gets confused by the Korean characters in the path (your name). Try upgrading pandoc, or, better yet, use Quarto.

Related

Unable to find file 'path/NA' when knitting to word_document2 using tbl_summary but works for PDF, HTML etc

before you click "next", this is not a path file error.
I am building on a blogpost: https://labrtorian.com/2019/08/26/rmarkdown-template-that-manages-academic-affiliations/
It works well for scientific papers.
My problem is:
In Rmarkdown when calling a data frame I am returned with the error about not being able to find file 'path/NA'
---
output:
bookdown::word_document2:
pandoc_args:
- --reference-doc=Extras/Reference_Document.docx
keep_tex: TRUE
---
```{r MRE}
library(gtsummary)
a <- c(10,20,30,40)
b <- c('book', 'pen', 'textbook', 'pencil_case')
c <- c(TRUE,FALSE,TRUE,FALSE)
d <- c(2.5, 8, 10, 7)
df <- data.frame(a,b,c,d)
tbl_summary(df)
tbl_summary
which returns:
Error: could not find file '/Users/brianbrummer/Documents/Rstudio/Affilitations_template/NA'
Execution halted
So what gives? I would usually know how to fix a "path not found" error, but not a file...and the file is NA?
files referenced in YAML can be found:
https://github.com/bridaybrummer/author_affiliations_extras.git
Thanks in advance
I did some digging and found the issue and a solution. First, if you update your yaml to call the reference document like this, you won't get the error any longer.
---
output:
word_document:
reference_doc: Reference_Document.docx
---
The issue was with the flextable package. If you're looking for community service points, you can post this reprex to their github page to alert them to the issue.
---
output:
word_document:
pandoc_args:
- --reference-doc=Reference_Document.docx
---
```{r MRE}
mtcars |>
flextable::flextable()
```

Problem with the preview in the ioslides presentation

I am using the ioslides_presentation output. I have some latex code. In my preview (after knitting), I always see a return before each latex symbol. As the following shows
If I view it in the browser, it is perfectly fine
What is wrong with my preview? How should I set it up as the view in the browser?
I attach the source code and compiling report. Thank you!
---
title: "Bla Bla "
subtitle: "sss"
author: "Joey"
date: '`r format(Sys.Date(), format="%B %d, %Y")`'
output:
ioslides_presentation
---
##
If $\alpha\in[\frac{1}{8},1)\backslash \{1/3\}$, then a shrinker of ?? is a shrinking circle.
If $\alpha=\frac{1}{3}$, then a shrinker is a shrinking ellipsoid.
If $\alpha \in (0,\frac{1}{8})$, then a shrinker is a circle
or a curve ${\Gamma_{\alpha}^k}$ with $k$-fold symmetry,
|......................................................................| 100%
inline R code fragments
/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc +RTS -K512m -RTS test.utf8.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output test.html --email-obfuscation none --self-contained --variable transition=0.4 --template /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rmarkdown/rmd/ioslides/default.html --include-in-header /var/folders/yb/7mjccgyj7sg0_04sv3pxnnxc0000gn/T//Rtmpo5qpXF/rmarkdown-str501875693231.html --mathjax --variable 'mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
output file: test.knit.md
/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc +RTS -K512m -RTS test.utf8.md --to ioslides_presentation.lua --from markdown+autolink_bare_uris+tex_math_single_backslash --output /var/folders/yb/7mjccgyj7sg0_04sv3pxnnxc0000gn/T//Rtmpo5qpXF/ioslides-output50184d5e6b2f.html --slide-level 2
Output created: test.html

Render to "pdf_document" output format in rmarkdown getting stuck on knitr asis_output function

New to Rmarkdown (and markdown in general). I've inherited some code that works great for the html_document output format but not for pdf_document. It seems to get stuck on the knitr asis_output function in the .Rmd script. When I comment out chunks containing that function, it writes to pdf no problem. Here's some troubleshooting I've tried:
xfun::session_info('rmarkdown')
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.1, RStudio 1.2.1335
Random number generation:
RNG: Mersenne-Twister
Normal: Inversion
Sample: Rounding
Locale: en_CA.UTF-8 / en_CA.UTF-8 / en_CA.UTF-8 / C / en_CA.UTF-8 / en_CA.UTF-8
:Package version:
base64enc_0.1.3 digest_0.6.20 evaluate_0.14 glue_1.3.1 graphics_3.6.1 grDevices_3.6.1 highr_0.8
htmltools_0.4.0 jsonlite_1.6 knitr_1.25 magrittr_1.5 markdown_1.1 methods_3.6.1 mime_0.7
Rcpp_1.0.2 rlang_0.4.0 rmarkdown_1.16 stats_3.6.1 stringi_1.4.3 stringr_1.4.0 tinytex_0.17.1
tools_3.6.1 utils_3.6.1 xfun_0.10 yaml_2.2.0
Pandoc version: 2.7.3
Sys.getenv('PATH')
[1] "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin:/opt/X11/bin"
tinytex::tinytex_root()
[1] "/usr/local/texlive/2019"
(tinytex::tlmgr_path())
tlmgr path add add_link_dir_dir: /usr/local/share/info/dir exists;
not making symlink. add_link_dir_dir: destination
/usr/local/share/man/man5 not writable, no links from
/usr/local/texlive/2019/texmf-dist/doc/man/man5.tlmgr: An error has
occurred. See above messages. Exiting. add of symlinks had 1
error(s), see messages above.[1] 6
So maybe the problem is a path issue? In which case I have no clue how to fix. Or should I be using an alternative to the asis_output function? Any help is much appreciated. Here's the relevant bits of my code:
In the R script:
id <- 44
rmarkdown::render('mymarkdown.Rmd',
output_format = "pdf_document",
output_file = paste("report_", id,".pdf", sep=''),
output_dir = '/Users/myname/Documents/test')
In the Rmd file:
---
title: "Monitoring Activity Summary Report"
mode: selfcontained
date: "November 2019"
output:
pdf_document: default
html_document: default
self_contained: yes
---
[some code chunks...]
[then these code chunks that get stuck only for "pdf_document"...]
``` {r setup_Samp1a, echo=FALSE}
sampling_1 <- !is.na(sampling_unique[1])```
```{r conditional block, eval = sampling_1}
asis_output("### 3.1 Sampling 1\\n") # Header that is only shown if
sampling_1 == TRUE```
The error message
! Undefined control sequence.
<argument> 3.1 Sampling 1\n
Error: Failed to compile /Users/myname/Documents/test/report_44.tex.
See https://yihui.name/tinytex/r/#debugging for debugging tips. See
report_44.log for more info.

another LaTeX Error: Missing \begin{document} in rmarkdown

I'm automating a pdf report using rmarkdown. I use a macro to run the code. I can run the code once and it works with no problems. When I call the macro again, it appears to work but when creating a pdf, I get the error "LaTeX Error: Missing \begin{document}"
This is what I get the first time:
output file: L:/Statunit/morton/NCC R markdown reports/NCC Reports/NCC_Dashboard_Report_Dave.knit.md
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS "L:/Statunit/morton/NCC R markdown reports/NCC Reports/NCC_Dashboard_Report_Dave.utf8.md" --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output pandoc9e03c3032cf.tex --template "C:\Users\Mortond\Documents\R\win-library\3.5\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --latex-engine xelatex --variable graphics=yes --variable "geometry:margin=1in" --variable "compact-title:yes" --include-in-header "C:\Users\Mortond\AppData\Local\Temp\Rtmp8cWvvQ\rmarkdown-str9e022b75c22.html"
Output created: Report-254-225573.pdf
The second time, I call the same code but only change the report name, so the data is the same and I get.
output file: L:/Statunit/morton/NCC R markdown reports/NCC Reports/NCC_Dashboard_Report_Dave.knit.md
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS "L:/Statunit/morton/NCC R markdown reports/NCC Reports/NCC_Dashboard_Report_Dave.utf8.md" --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output pandoc9e01f0a74c5.tex --template "C:\Users\Mortond\Documents\R\win-library\3.5\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --latex-engine xelatex --variable graphics=yes --variable "geometry:margin=1in" --variable "compact-title:yes"
! LaTeX Error: Missing \begin{document}.
Error: Failed to compile Report-253-225573.tex. See Report-253-225573.log for more info.
my YAML is
---
title: ''
header-includes:
- \usepackage{fancyhdr}
- \addtolength{\headheight}{1.0cm} % make more space for the header
- \pagestyle{fancyplain} % use fancy for all pages except chapter start
- \lhead{\includegraphics[height=1.2cm]{TJC_logo_color.png}} % left logo
- \renewcommand{\headrulewidth}{0pt} % remove rule below header
output:
pdf_document:
latex_engine: xelatex
word_document: default
html_document: default
urlcolor: blue
classoption: landscape
---
my code that calls the markdown is :
render_report = function(b,h,p) {
rmarkdown::render(
"L:/Statunit/morton/NCC R markdown reports/NCC Dashboard Report
Dave.Rmd", params = list(
b1 = b,
h1 = h,
p1 = p
),
output_file = paste0("Report-", h, "-", p, ".pdf")
)
}
render_report(b="xxxx Hospital, Inc.",h='253',p='225573')
The log file with the error part is.
("C:\Users\Mortond\AppData\Local\Programs\MiKTeX 2.9\tex\latex\graphics-def\xet
ex.def"
File: xetex.def 2017/06/24 v5.0h Graphics/color driver for xetex
))
\Gin#req#height=\dimen160
\Gin#req#width=\dimen161
)
("C:\Users\Mortond\AppData\Local\Programs\MiKTeX 2.9\tex\latex\oberdiek\grffile
.sty"
Package: grffile 2017/06/30 v1.18 Extended file name support for graphics (HO)
Package grffile Info: Option `multidot' is set to `true'.
Package grffile Info: Option `extendedchars' is set to `false'.
Package grffile Info: Option `space' is set to `true'.
Package grffile Info: \Gin#ii of package `graphicx' fixed on input line 494.
)
("C:\Users\Mortond\AppData\Local\Programs\MiKTeX 2.9\tex\latex\parskip\parskip.
sty"
Package: parskip 2018-08-24 v2.0a non-zero parskip adjustments
)
("C:\Users\Mortond\AppData\Local\Programs\MiKTeX 2.9\tex\latex\titling\titling.
sty"
Package: titling 2009/09/04 v2.1d maketitle typesetting
\thanksmarkwidth=\skip53
\thanksmargin=\skip54
\droptitle=\skip55
)
("C:\Users\Mortond\AppData\Local\Programs\MiKTeX 2.9\tex\latex\fancyhdr\fancyhd
r.sty"
Package: fancyhdr 2017/06/30 v3.9a Extensive control of page headers and footer
s
\f#nch#headwidth=\skip56
\f#nch#O#elh=\skip57
\f#nch#O#erh=\skip58
\f#nch#O#olh=\skip59
\f#nch#O#orh=\skip60
\f#nch#O#elf=\skip61
\f#nch#O#erf=\skip62
\f#nch#O#olf=\skip63
\f#nch#O#orf=\skip64
)
! LaTeX Error: Missing \begin{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.90 \addtolength{\headheight}{1.0cm} \%
make more space for the header
Here is how much of TeX's memory you used:
22493 strings out of 427767
408844 string characters out of 3146884
530389 words of memory out of 3000000
26423 multiletter control sequences out of 15000+200000
532722 words of font info for 28 fonts, out of 3000000 for 9000
1328 hyphenation exceptions out of 8191
45i,0n,68p,816b,443s stack positions out of 5000i,500n,10000p,200000b,50000s
No pages of output.
So why does it work once and not a second time? If I exit RStudio and then s start it up again, it appears to work. I've tried to
.rs.restartR() to no avail. as well as
rm(list = ls(envir = globalenv()),envir = globalenv())
gc() to clean things up.
Any thoughts? I appreciate reading through all this.
I do not know if I had the same issue. But I experienced that if I compiled my document it worked the first time and failed the second. I suspected a cache issue and added cache.rebuild=T to
<<echo=F, cache=T, message=F, warning=F, `>>=
set_parent('../../Parent.Rnw')
#
Just FIY, the header of the parent does not only include the latex info but also sources my main .R file with the calculations.
Anyway, if someone experience a similar problem try to add cache.rebuild=T to your included script(s).

Where to put header.tex to change page to Landscape Rmarkdown

I read here how to add what is needed to give me the ability to change my page to landscape:
enter link description here
However I have saved the header.tex file everyplace I could think of and I still end up getting the following error:
Called from: (function (e)
{
if (inherits(e, "shiny.silent.error"))
return()
handle <- getOption("shiny.error")
if (is.function(handle))
handle()
})(list(message = "pandoc document conversion failed with error 43",
call = NULL))
Browse[1]>
I know this is do to me typing \blandscape and \elandscape because the PDF works as soon as I delete those commands. What I need help with is figuring out where to save the header.tex file to so that Rmarkdown knows how to locate it. Thanks in advance for everyone's your help!
Follow up:
Taking scoa's advice about adding it to my header I edited the top of my Rmd file to the following. Unfortunately it still didn't work.
---
title: "Lake Report"
output: pdf_document
header-includes:
- \usepackage{lscape}
- \newcommand{\blandscape}{\begin{landscape}}
- \newcommand{\elandscape}{\end{landscape}}
---
\newpage
\blandscape
```{r Non-Seasonal MK results, echo=FALSE}
# MKanalysis <- reactive(HM_MK(data = NonSeasonalData(),n = 4))
kable(MKanalysis(), caption = "Non-Seasonal Trend Analysis")
```
The results of the Mann Kendall analysis....
\elandscape
Latex program/verision: pdfTex, Version 3.14159265-2.6-1.40.17
Save the header.tex in the same directory your Rmd file is. Also, rather than an external file, you could just add those commands in your yaml front matter, a more portable solution:
---
title: "Lake Report"
output: pdf_document
header-includes:
- \usepackage{lscape}
- \newcommand{\blandscape}{\begin{landscape}}
- \newcommand{\elandscape}{\end{landscape}}
---