#Create a string scalar
base <- "A"
#Glue
stringr::str_glue("Adenine is represented by the letter {base}")Adenine is represented by the letter A
The function stringr::str_glue() is similar to str_c() but allows you to include variable names within double quotes.
Variables to be used are flanked by curly braces, e.g. "{variable_name}".
You can include a string variable into a string specified in stringr::glue().
Adenine is represented by the letter A
You can include multiple variables.
The complementary base of A is T
Like paste0() or str_c() you can combine multiple strings and set a separator. In this case the option is .sep=.
T is a nucleic acid DNA base. U is a nucleic acid RNA base.
If you need to display something such as {base} you can use double braces ({{base}}).
Additionally we will use a new space (\n) as the separator.
Non strings are converted into strings.
There are 4 DNA bases
With numerics you can carry out maths in the braces.
[1] │ There are 2 purines.
│ There are 3 pyrimidines
Below shows how logicals and missing values work.
Using vectors with str_glue() works the same way as str_c().
[1] │ A DNA base is A
[2] │ A DNA base is G
[3] │ A DNA base is C
[4] │ A DNA base is T
When using multiple vectors ensure they are the same length.
[1] │ Adenine is represented by A
[2] │ Guanine is represented by G
[3] │ Cytosine is represented by C
[4] │ Thymine is represented by T
Using vectors of different lengths will lead to an error but you can always use scalars with vectors.
[1] │ The DNA base Adenine is represented by A
[2] │ The DNA base Guanine is represented by G
[3] │ The DNA base Cytosine is represented by C
[4] │ The DNA base Thymine is represented by T