From wdunlap at tibco.com  Mon Jul 21 17:20:46 2014
From: wdunlap at tibco.com (William Dunlap)
Date: Mon, 21 Jul 2014 08:20:46 -0700
Subject: [Rd] Question on Code snippet semantics
In-Reply-To: <53CD2CAD.6010503@oracle.com>
References: <53CD2CAD.6010503@oracle.com>
Message-ID: <CAF8bMcaivRtofk+UFB+0w6FCijKwn5wZZvMbczK2PpDaZiQndw@mail.gmail.com>

subsitute(expr), with only one argument, is only useful inside of a
function and then only when the expression, expr, involves an argument
to the function.  Then the unevaluated actual arguments to the
function are substituted into the [unevaluated] expression.

E.g.,
   f <- function(x, y=stop("y is required"), z=log(-1)) {
      substitute(y + z)
   }
   f(1)
   # stop("y is required") + log(-1)
   f(1,sqrt(-1),log(1:10))
   # sqrt(-1) + log(1:10)

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Jul 21, 2014 at 8:07 AM, Mick Jordan <mick.jordan at oracle.com> wrote:
> I came across this code in library.R
>
> package <- as.character(substitute(package))
>
> where package is the first argument to the "library" function.
>
> I've been racking my brains to understand why this is not just an elaborate
> (and ineffcient) way to write:
>
> package <- "package"
>
> E.g.
>
>> package <- as.character(substitute(package))
>> package
> [1] "package"
>>
>
> Thanks
> Mick Jordan
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Question on Code snippet semantics
William Dunlap