0

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.

Josh
  • 1,210
  • 12
  • 30
  • Answer from jemus42 on RStudio community site: "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 $?" – Josh Mar 27 '19 at 20:42

1 Answers1

1

You can use ${2:$} to add a "$" sign.

For instance:

${1: mydata}${2:$}added_data

For your example this should work:

.env${2:$}${1:package} <- ${1:package}
elcortegano
  • 2,444
  • 11
  • 40
  • 58