Skip to content
Prev 363323 / 398502 Next

Help with non standard evaluation and require function

Hi David and Duncan,
thanks for your answers!

I think what is not clear to me is actually how "substitute" works.

If I run require (dplyr) or require("dplyr") in the R console everything
works as I expect even without the character.only=T (actually because of
this I always interpreted that character.only=F means you can either use
nse or strings while with character.only=T you can only use strings).

What I don't understand is why in the require function

as.character (substitute(package))

returns "pkgname" (the name of the variable I use in my function) rather
than substituting the value of pkgname i.e. dplyr in my example.

I have no access to my laptop so I can't double check but I think in one of
Wickham's book there was an example like

f <- function (y) {
  substitute (x + y)
}

f(4)
[1] x + 4

i.e. where substitute inside a function was substituting the value of y and
returned the expression replacing y with 4, which is what I would expect to
happen.

It is probaby a very trivial problem but I find hard to figure out ho
substitute works.

Thanks a lot again for the help!
Cheers,
Luca
On Aug 12, 2016 20:14, "David Winsemius" <dwinsemius at comcast.net> wrote: