R functions glue vs paste

Viewed 2891

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:

  • According to this site, glue is slower than paste.
  • The syntax of glue is similar and in no way easier to read than the syntax of 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.

1 Answers

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.

Related