I recently discovered the glue package.
After a little bit of research I couldn't figure out why glue::glue
should be preferred over paste
:
paste
.However, in the link from above, the authors say that paste
does not do string interpolation (only string insertion). I don't really know what this means.
Can some clarify why the glue
package is interesting and what is meant by string insertion?
Thank you in advance.
EDIT: After the first feedback I want to ask a more precise question.
Are there any situations where one of paste
or glue
would clearly be preferred over the other?
I am trying to understand why someone put in the effort to create the glue package.
Overview. Glue offers interpreted string literals that are small, fast, and dependency-free. Glue does this by embedding R expressions in curly braces which are then evaluated and inserted into the argument string.
Adhesive, also known as glue, cement, mucilage, or paste, is any non-metallic substance applied to one or both surfaces of two separate items that binds them together and resists their separation.
Package {glue} is designed as “small, fast, dependency free” tools to “glue strings to data in R”. To put simply, it provides concise and flexible alternatives for. paste() with some additional features: library(glue)
Wikipedia says :
In computer programming, string interpolation (or variable interpolation, variable substitution, or variable expansion) is the process of evaluating a string literal containing one or more placeholders, yielding a result in which the placeholders are replaced with their corresponding values.
paste
doesn't look into the strings that are passed to it to replace some characters by others, that's why it doesn't do interpolation.
According to this definition I'm not sure why one would say sprintf
doesn't do interpolation (as it's mentioned on your link), it might be because the placeholders are not explicit as they are in glue, but I think this assertion is debatable.
Your question about why glue is good is unfortunately out of scope here as it's a matter of opinion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With