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:

source("C:/R/Functions/[inserted_text].R")
.env$[inserted_text] <- [inserted_text]

I tried using the following snippet:

snippet srcfnc
    source('C:/Users/JT/R/Functions/${1:package}.R')
    .env$${1:package} <- ${1:package}

Unfortunately, this gives the result below:

source('C:/Users/JT/R/Functions/[inserted_text].R')
.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
	.env${1:package}
	.env$${1:package}
	.env$$${1:package}
	.env\$${1:package}
	.env\$$${1:package}

but I get these results:

.env[inserted_text]
.env{1:package}
.env[inserted_text]
.env\{1:package}
.env${1:package}

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.