如何轉義雙引號以在命令列上運行此代碼塊?有問題的代碼部分是paste('! LaTeX Error: File', paste0("`", x, "'.sty'"), 'not found.')).
Rscript \
-e "biosketch_pkgs <- list('microtype', 'tabu', 'ulem', 'enumitem', 'titlesec')" \
-e "lapply(biosketch_pkgs, function (x) {tinytex::parse_install(text=paste('! LaTeX Error: File', paste0("`", x, "'.sty'"), 'not found.'))})"
我嘗試使用以下內容轉義雙引號,但它回傳unexpected EOF while looking for matching ''`
Rscript \
-e "biosketch_pkgs <- list('microtype', 'tabu', 'ulem', 'enumitem', 'titlesec')" \
-e "lapply(biosketch_pkgs, function (x) {tinytex::parse_install(text=paste('! LaTeX Error: File', paste0("\`"\, x, "\'.sty'"\), 'not found.'))})"
uj5u.com熱心網友回復:
與其擔心如何轉義特定的字串,不如考慮以一種完全避免需要進行任何轉義的方式處理它們。RunningRscript -告訴 Rscript 讀取源代碼以在 stdin 上運行,同時<<'EOF'使所有內容到下一行只包含EOF在 stdin 上。(您可以將字符替換為EOF您選擇的任何其他符號,但重要的是參考或轉義此符號以指示外殼不要以任何方式修改內容)。
Rscript - <<'EOF'
biosketch_pkgs <- list('microtype', 'tabu', 'ulem', 'enumitem', 'titlesec')
lapply(biosketch_pkgs, function (x) {
tinytex::parse_install(text=paste('! LaTeX Error: File',
paste0("`", x, "'.sty'"),
'not found.'))
})
EOF
但是,如果您確實有令人信服的理由使用Rscript -e,則正確的轉義將在反斜杠、雙引號或其他對雙引號字串中的 shell 有意義的語法之前放置反斜杠,如下所示:
Rscript \
-e "biosketch_pkgs <- list('microtype', 'tabu', 'ulem', 'enumitem', 'titlesec')" \
-e "lapply(biosketch_pkgs, function (x) {tinytex::parse_install(text=paste('! LaTeX Error: File', paste0(\"\`\", x, \"'.sty'\"), 'not found.'))})"
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/509827.html
標籤:r重击小特克斯
上一篇:通過匹配多個通配符值批量處理音頻檔案和影像檔案以創建電影檔案
下一篇:檔案后綴不匹配的Glob
