0

Rmarkdown 的新手(以及一般的降价)。我继承了一些适用于 html_document 输出格式但不适用于 pdf_document 的代码。它似乎卡在 .Rmd 脚本中的 knitr asis_output 函数上。当我注释掉包含该函数的块时,它写入 pdf 没有问题。这是我尝试过的一些故障排除:

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

所以也许问题是路径问题?在这种情况下,我不知道如何解决。还是我应该使用 asis_output 函数的替代方法?任何帮助深表感谢。这是我的代码的相关位:

在 R 脚本中:

id <- 44

rmarkdown::render('mymarkdown.Rmd',
              output_format = "pdf_document",
              output_file =  paste("report_", id,".pdf", sep=''), 
              output_dir = '/Users/myname/Documents/test')

在 Rmd 文件中:

---
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```

错误信息

! 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.
4

0 回答 0