how to interpret the code below , how R treat and evaluate it and get the result "foo",it is hard to understand for me
`foo}\`` <- "foo"
glue("{
{
'}\\'' # { and } in comments, single quotes
\"}\\\"\" # or double quotes are ignored
`foo}\\`` # as are { in backticks
}
}")
#> foo
You're not the only one to find this example difficult to read.
First, a variable with a funny name is created, and assigned the value "foo":
Then
glue
should evaluate an R expression contained in the first level of curly braces, and itself contained in curly braces:As it's a string, backslashes are used to be able to write special characters.
When R parses each line of the expression, it converts the special characters to their value, and removes the comments after
#
.The first line of the expression becomes
The second line of the expression becomes:
And finally the last line:
To sum up, we have :