I created the following snippet:
snippet setttwd
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
But when I type setttwd
and press enter, I get the following piece of code:
Note that $path
has disappeared.
Why?
CodePudding user response:
Because $ is used as a special character to denote where the cursor should jump after completing each section of a snippet, in order to insert a literal $ it must be escaped as \$.
https://rstudio.github.io/rstudio-extensions/rstudio_snippets.html#customizing-snippets
CodePudding user response:
Replacing $
by \$
solved the issue
snippet setttwd
setwd(dirname(rstudioapi::getActiveDocumentContext()\$path))