0

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.
cmort
  • 3
  • 4
  • I guess you need a single backslash instead of two (i.e. `\n` instead of `\\n`). – Yihui Xie Nov 04 '19 at 02:42
  • Omg. You are absolutely right. I assumed that was just something unique to markdown for 'double space' or something. Thank you! Is it weird that it worked fine for html with the double backslash? Or is that expected behaviour for html? – cmort Nov 04 '19 at 09:25

0 Answers0