我创建了以下代码片段:
snippet setttwd
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))

但是,当我输入setttwd并按enter键时,我会得到以下代码:

注意,$path已经消失了。
为什么?
发布于 2022-11-17 12:30:07
,因为$被用作一个特殊字符,用于表示游标在完成代码段的每个部分后应该跳到哪里,为了插入文字$,必须将其转义为\$。
https://rstudio.github.io/rstudio-extensions/rstudio_snippets.html#customizing-snippets
发布于 2022-11-17 13:02:25
用$取代\$解决了这个问题
snippet setttwd
setwd(dirname(rstudioapi::getActiveDocumentContext()\$path))https://stackoverflow.com/questions/74473263
复制相似问题