【问题标题】:Problem knitting cv templates in the R package vitae在 R 包简历中编织 cv 模板时出现问题
【发布时间】:2021-07-25 05:43:55
【问题描述】:

当我在 R 包简历中编织任何 CV 模板时,每个模板都会出现稍微不同的错误。我确保所有文件,包括我的 Rmd 文件,都在同一个目录中,并且我没有以任何方式更改模板。例如,当我编写现代 CV 模板时,我收到以下错误消息:

! Package inputenc Error: Unicode character € (U+20AC)
(inputenc)                not set up for use with LaTeX.

Try other LaTeX engines instead (e.g., xelatex) if you are using pdflatex. See https://bookdown.org/yihui/rmarkdown-cookbook/latex-unicode.html
Error: LaTeX failed to compile MWillox.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See MWillox.log for more info.
In addition: Warning messages:
1: In has_crop_tools() : 
Tool(s) not installed or not in PATH: ghostcript
-> As a result, figure cropping will be disabled.
2: package 'tibble' was built under R version 4.0.5 
3: package 'dplyr' was built under R version 4.0.5 
Execution halted

当我选择了很棒的简历模板时,错误信息略有不同:

! Undefined control sequence.
<argument> \fontspec_gset_family:Nnn 
                                     \g__fontspec_mathsf_tl { UprightFont = ...
l.123 ^^I\fi

其余错误信息同上。

我尝试更新我的所有软件包。我重新安装了 Rtools、pandoc 和 ghostcript。我确保环境路径都在那里并且指向正确的目录,遵循这个advice

这两个错误似乎表明我在 Rmd 或 bib 文件中的某些字体或符号存在问题,但这似乎不太可能,因为我没有对模板进行任何更改,所以我很难过。

我是 R Markdown 的一个相对较轻的用户,所以我会很感激一些介绍性的建议。

这是我的会话信息:

- Session info ----------------------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 4.0.2 (2020-06-22)
 os       Windows 10 x64              
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  English_Canada.1252         
 ctype    English_Canada.1252         
 tz       America/New_York            
 date     2021-05-02                  

- Packages --------------------------------------------------------------------------------------------------------------------------------------------
 package     * version date       lib source        
 assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.0.2)
 cli           2.5.0   2021-04-26 [1] CRAN (R 4.0.5)
 crayon        1.4.1   2021-02-08 [1] CRAN (R 4.0.5)
 DBI           1.1.1   2021-01-15 [1] CRAN (R 4.0.5)
 digest        0.6.27  2020-10-24 [1] CRAN (R 4.0.5)
 dplyr         1.0.5   2021-03-05 [1] CRAN (R 4.0.5)
 ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.0.2)
 evaluate      0.14    2019-05-28 [1] CRAN (R 4.0.2)
 fansi         0.4.2   2021-01-15 [1] CRAN (R 4.0.5)
 generics      0.1.0   2020-10-31 [1] CRAN (R 4.0.5)
 glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.5)
 htmltools     0.5.1.1 2021-01-22 [1] CRAN (R 4.0.5)
 knitr         1.33    2021-04-24 [1] CRAN (R 4.0.5)
 lifecycle     1.0.0   2021-02-15 [1] CRAN (R 4.0.4)
 magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.0.5)
 pillar        1.6.0   2021-04-13 [1] CRAN (R 4.0.5)
 pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.0.2)
 purrr         0.3.4   2020-04-17 [1] CRAN (R 4.0.2)
 R6            2.5.0   2020-10-28 [1] CRAN (R 4.0.5)
 rlang         0.4.11  2021-04-30 [1] CRAN (R 4.0.2)
 rmarkdown     2.7     2021-02-19 [1] CRAN (R 4.0.5)
 rstudioapi    0.13    2020-11-12 [1] CRAN (R 4.0.5)
 sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.2)
 tibble        3.1.1   2021-04-18 [1] CRAN (R 4.0.5)
 tidyselect    1.1.1   2021-04-30 [1] CRAN (R 4.0.2)
 utf8          1.2.1   2021-03-12 [1] CRAN (R 4.0.5)
 vctrs         0.3.8   2021-04-29 [1] CRAN (R 4.0.2)
 vitae       * 0.4.2   2021-02-17 [1] CRAN (R 4.0.5)
 withr         2.4.2   2021-04-18 [1] CRAN (R 4.0.5)
 xfun          0.22    2021-03-11 [1] CRAN (R 4.0.4)
 yaml          2.2.1   2020-02-01 [1] CRAN (R 4.0.0)

awesome-cv 模板代码应该对每个人都一样,但这里只是以防万一:

---
name: Marie
surname: Curie
position: "Professor"
address: "School of Physics & Chemistry, Ãcole Normale Supérieure"
phone: +1 22 3333 4444
www: mariecurie.com
email: "Marie.Curie@ens.fr"
twitter: mariecurie
github: mariecurie
linkedin: mariecurie
date: "`r format(Sys.time(), '%B %Y')`"
output: vitae::awesomecv
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
library(vitae)
```

# Some stuff about me

 * I poisoned myself doing research.
 * I was the first woman to win a Nobel prize
 * I was the first person and only woman to win a Nobel prize in two different sciences.

# Education

```{r}
library(tibble)
tribble(
  ~ Degree, ~ Year, ~ Institution, ~ Where,
  "Informal studies", "1889-91", "Flying University", "Warsaw, Poland",
  "Master of Physics", "1893", "Sorbonne Université", "Paris, France",
  "Master of Mathematics", "1894", "Sorbonne Université", "Paris, France"
) %>% 
  detailed_entries(Degree, Year, Institution, Where)
```

# Nobel Prizes

```{r}
tribble(
  ~Year, ~Type, ~Desc,
  1903, "Physics", "Awarded for her work on radioactivity with Pierre Curie and Henri Becquerel",
  1911, "Chemistry", "Awarded for the discovery of radium and polonium"
) %>% 
  brief_entries(
    glue::glue("Nobel Prize in {Type}"),
    Year, 
    Desc
  )
```

# Publications

```{r}
library(dplyr)
knitr::write_bib(c("vitae", "tibble"), "packages.bib")

bibliography_entries("packages.bib") %>%
  arrange(desc(author$family), issued)
```

我认为使用 MikTex 可能是问题的根源,所以我卸载了它和 tinytex。我重新安装了tinytex,但这并没有解决问题。它确实改变了错误信息:

output file: Awesome.knit.md

Error running filter C:\Users\micha\AppData\Local\Temp\Rtmp65nI7U/multiple-bibliographies.lua:
[string "C:\Users\micha\AppData\Local\Temp\Rtmp65nI7U/..."]:34: attempt to compare string with table
stack traceback:
    [string "C:\Users\micha\AppData\Local\Temp\Rtmp65nI7U/..."]:34: in function <[string "C:\Users\micha\AppData\Local\Temp\Rtmp65nI7U/..."]:32>
    [string "C:\Users\micha\AppData\Local\Temp\Rtmp65nI7U/..."]:32: in main chunk
Error: pandoc document conversion failed with error 83
In addition: Warning messages:
1: Detected pandoc version 2.7.2, which may cause issues with bibliography_entries().
Please update pandoc if you have any issues knitting bibliographies (this can be done by updating RStudio). 
2: In has_crop_tools() : 
Tool(s) not installed or not in PATH: pdfcrop, ghostcript
-> As a result, figure cropping will be disabled.
3: package 'tibble' was built under R version 4.0.5 
4: package 'dplyr' was built under R version 4.0.5 
Execution halted

【问题讨论】:

  • 欢迎来到 SO,@Michael!看来您正在使用一些特殊字符。您能否向我们提供您的 YAML 标头?
  • @Michael 您能否在您的问题中添加minimal reproducible example,以便我们重现问题?
  • 当然。我从模板中选择了 Curriculum Vitae(Awesome-CV 格式),将其命名为 Awesome,并选择“C:\test_vitae\”作为位置,然后单击“确定”。模板的 R markdown 脚本显示为“Awesome.Rmd”。我单击了 knit 并得到了与以前相同的错误。目录中有 5 个文件(“packages.bib”、“awesome-cv.cls”、“awesome.log”、“awesome.Rmd”和“awesome.tex”)加上一个名为“fonts”的文件夹,其中包含 11 .ttf 文件。我没有编辑 awesome-cv 模板的代码,但我会更新我的原始问题以包含它。我也刚刚试用了 Hyndman 的模板,效果很好。
  • @Michael 感谢您更新问题!如果我用address: "School of Physics &amp; Chemistry, École Normale Supérieure" 替换address: "School of Physics &amp; Chemistry, Ãcole Normale Supérieure" 你的代码对我来说很好。我想知道您的乳胶版本是否太旧。如果你运行pdflatex -v,你会得到什么?
  • @samcarter_is_at_topanswers.xyz,我通过重新安装 R Studio 解决了这个问题。这种方法似乎是一种蛮力的解决方法,而不是真正的解决方案。如果您有任何想法要分享,我很乐意了解更多有关找到合适解决方案的有用方法。非常感谢。

标签: r pdf latex r-markdown pandoc


【解决方案1】:

卸载MikTex后重新安装R Studio,最后安装R包tinytex的组合工作。

我认为@samcarter_is_at_topanswers.xyz 是对的,“问题在于过时的乳胶版本。utf8 前段时间成为默认编码,但如果您的 tex 版本较旧,那么这些特殊字符会导致问题。”

经验教训:

  1. tinytex 包是 R Markdown 所需的全部。您甚至可以在 R Studio 中打开 tex 文件来编辑它们并将它们编译为 pdf。看看如何安装它here

  2. 经常更新 MikTex。我假设它会在需要时自动更新,但这似乎不是真的。 Windows > MikTex > 更新。就是这么简单。如果您决定使用它,记住这样做是另一回事。

  3. 在这种情况下,能够检查环境路径是否都存在并指向正确的目录并没有帮助,但学习起来很好。这个link 很有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多