Home > Blockchain >  Why does the part after `$` disappear when an RStudio snippet is entered?
Why does the part after `$` disappear when an RStudio snippet is entered?

Time:11-17

I created the following snippet:

snippet setttwd
    setwd(dirname(rstudioapi::getActiveDocumentContext()$path))

enter image description here

But when I type setttwd and press enter, I get the following piece of code:

enter image description here

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))
  • Related