Handlebars - output a value inside curly braces [duplicate] - handlebars.js

This question already has an answer here:
Simple way to escape curly braces?
(1 answer)
Closed 5 years ago.
My output needs to look somewhat like:
{foo} bar
The problem is the value foo comes from either a field or a helper. I could make the helper include the brackets {foo} but that doesn't seem a perfect solution. On the other hand if I try:
{{{foo_field}}} {{bar_field}}
That doesn't work as tripple braces also render the field in a slightly different manner.

Solution copied from Simple way to escape curly braces?
{ {{~foo_field~}} } {{bar_field}}

Related

In R, how to change working directory more easily? [duplicate]

This question already has answers here:
Escaping backslash (\) in string or paths in R
(4 answers)
Closed 1 year ago.
In how to change working directory more easily?
Currently, if we use 'setwd',we have to add many '\', sometimes it's boring
Is there any easier way for this ? (Just like Python can add 'r' )
setwd('C:\Users\Administrator\Desktop\myfolder') # can't work
setwd('C:\\Users\\Administrator\\Desktop\\myfolder') # can work,but havt to add many '\'
You could use r (for raw string) and add parenthesis:
> r"(C:\Users\Administrator\Desktop\myfolder)"
[1] "C:\\Users\\Administrator\\Desktop\\myfolder"
>
And now:
setwd(r"(C:\Users\Administrator\Desktop\myfolder)")
Or reading from clipboard automatically adds the extra slashes:
setwd(readClipboard())

Remove multiple instances with a regex expression, but not the text in between instances [duplicate]

This question already has answers here:
Regular expression to stop at first match
(9 answers)
Closed 1 year ago.
In long passages using bookdown, I have inserted numerous images. Having combined the passages into a single character string (in a data frame) I want to remove the markdown text associated with inserting images, but not any text in between those inserted images. Here is a toy example.
text.string <- "writing ![Stairway scene](/media/ClothesFairLady.jpg) writing to keep ![Second scene](/media/attire.jpg) more writing"
str_remove_all(string = text.string, pattern = "!\\[.+\\)")
[1] "writing more writing"
The regex expression doesn't stop at the first closed parenthesis, it continues until the last one and deletes the "writing to keep" in between.
I tried to apply String manipulation in R: remove specific pattern in multiple places without removing text in between instances of the pattern, which uses gsubfn and gsub but was unable to get the solutions to work.
Please point me in the right direction to solve this problem of a regex removal of designated strings, but not the characters in between the strings. I would prefer a stringr solution, but whatever works. Thank you
You have to use the following regex
"!\\[[^\\)]+\\)"
alternatively you can also use this:
"!\\[.*?\\)"
both solution offer a lazy match rather than a greedy one, which is the key to your question
I think you could use the following solution too:
gsub("!\\[[^][]*\\]\\([^()]*\\)", "", text.string)
[1] "writing writing to keep more writing"

Replace latex with r strings using gsub [duplicate]

This question already has an answer here:
"'\w' is an unrecognized escape" in grep
(1 answer)
Closed 1 year ago.
I would like to find and replace tabular instances by tabularx. I tried with gsub but it seems to enter me into a world of escaping pain. Following other questions and answers I find fixed=TRUE which is the best I so far have. The code snippet below almost works, \B is unrecognized. If I escape it twice I get \BEGIN as output!
texText <- '\begin{tabular}{rl}\begin{tabular}{rll}'
texText <- gsub("\begin{tabular}{rl}", "\BEGIN{tabular}{rll}", texText, fixed=TRUE)
I'm using BEGIN as my test to see what is happening. This is before I get to tackling the question of what goes on in the brackets {rl} {ll} {rrl} etc. Ideally I'm looking for a regex that would output:
\begin{tabularx}{rX}\begin{tabularx}{rlX}
That is the final column is replaced by X.
Try using proper escaping:
texText <- "\begin{tabular}{rl}\begin{tabular}{rll}"
output <- gsub("\begin\\{tabular\\}", "\begin{tabularx}", texText)
output
[1] "\begin{tabularx}{rl}\begin{tabularx}{rll}"
A literal backslash requires two backslashes, and also metacharacters such as { and } require two backslashes.

How to put \' in my string using paste0 function [duplicate]

This question already has answers here:
How to escape backslashes in R string
(3 answers)
Closed 5 years ago.
I have an array:
t <- c("IMCR01","IMFA02","IMFA03")
I want to make it look like this:
"\'IMCR01\'","\'IMFA02\'","\'IMFA03\'"
I tried different ways like:
paste0("\'",t,"\'")
paste0("\\'",t,"\\'")
paste0("\\\\'",t,"\\\\'")
But none of them is correct. Any other functions are OK as well.
Actually your second attempt is correct:
paste0("\\'",t,"\\'")
If you want to tell paste to use a literal backslash, you need to escape it once (but not twice, as you would need within a regex pattern). This would output the following to the console in R:
[1] "\\'IMCR01\\'" "\\'IMFA02\\'" "\\'IMFA03\\'"
The trick here is that the backslash is even being escaped by R in the console output. If you were instead to write t to a text file, you would only see a single backslash as you wanted:
write(t, file = "/path/to/your/file.txt")
But why does R need to escape backslash when writing to its own console? One possibility is that if it were to write a literal \n then this would actually be interpreted by the console as a newline. Hence the need for eacaping is still there.

Disable underscore "_" shortcut inserting "<-" in Vim R plugin [duplicate]

This question already has answers here:
Vim: underscore(_) automatically converted to (<-)
(4 answers)
Closed 8 years ago.
By default, the Vim-R-plugin inserts <- whenever I type or paste an underscore _. This creates problems when I paste stuff like geom_bar, which becomes geom <- bar. Is there a way to turn this short-cut off?
I tried looking at the manual (scroll down to Edit section) but couldn't figure out how to do it.
I'm using Vim-R-plugin Version 0.9.9.9
for Vim version 7.4.
From the help page of the plugin:
6.3. Assignment operator and Rnoweb completion of code block
...
To completely disable this feature, put in your vimrc:
let vimrplugin_assign = 0
--
EDIT: As of writing this (2019-10-25), add this to your vimrc instead:
6.4. Assignment operator and Rnoweb completion of code block
...
let R_assign = 0

Resources