Escaping $ dollar sign character in RStudio snippets

I want to write a snippet that will allow me to put a string of text in multiple locations in my code, including after a $, to give the following expected result:

.env$[inserted_text] <- [inserted_text]

I tried using the following snippet:

snippet srcfnc
    .env$${1:package} <- ${1:package}

Unfortunately, this gives the result below:

.env{1:package} <- [inserted_text]

I've looked here and here, but none of the suggested solutions work in RStudio. I've also tried escaping the $ with \ as suggested here

snippet test

but I get these results:


Any suggestions? Thanks.

Does it have to be .env$something ? I thought the point of $ was to enable users to not have to write e.g. .env[[something]] (or with single brackets, depending).

Point being: Can you get it to work with bracket notation instead of $?

Hah, good point. Apparently, $ is not supposed to be used programmatically (see here)!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.