R包简历中的问题编织简历模板

Problem knitting cv templates in the R package vitae

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

! 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

当我选择 awesome CV 模板时,错误信息略有不同:

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

其余错误信息同上。

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

这两个错误似乎表明我的 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

卸载 MikTex 后重新安装 R Studio,最后安装 R 包 tinytex 的组合成功了。

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

经验教训:

  1. R Markdown 只需要 tinytex 包。您甚至可以在 R Studio 中打开 tex 文件,将它们编辑并编译为 pdf。查看如何安装它here

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

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