The problem is this:
- You want to insert some text between backticks
- A snippet interprets backticks as a signal to evaluate the code
So you need to find a way to insert the backticks in a way that doesn't trigger evaluation.
You can do this by using the following snippet definition:
snippet tod
`r quote('\u0060r format(Sys.time(), "%Y-%m-%d")\u0060')`
This works because:
-
`r ...` tells the snippet to evaluate the code
-
quote() allow you to define an expression that will be evaluated later
-
\u0060 is the unicode encoding for a backtick
Footnote:
To determine what the unicode encoding for any character is, use the function iconv():
> iconv("`", from = "ascii", toRaw = TRUE)
[[1]]
[1] 60
To convert from unicode to ASCII, again use iconv():
> iconv("\u0060", to = "ASCII")
[1] "`"