From lionel at rstudio.com  Wed Mar 22 20:06:52 2017
From: lionel at rstudio.com (Lionel Henry)
Date: Wed, 22 Mar 2017 20:06:52 +0100
Subject: [Rd] RFC: (in-principle) native unquoting for standard evaluation
In-Reply-To: <20170319183610.GA26048@mail.cs.toronto.edu>
References: <mailman.9.1489921202.31343.r-devel@r-project.org>
	<20170319183610.GA26048@mail.cs.toronto.edu>
Message-ID: <99be949c-16b8-685d-91f0-54afc9ff1566@rstudio.com>


RN> There is an opportunity cost to grabbing the presently-unused unary @
RN> operator for this

I don't think this is the case because the parser has to interpret `@`
in formal argument lists in a different way than in function calls.
Besides, it'd make sense to set up these annotations with a binary
`@`. There are already two main ways of passing arguments in R: by
value and by expression. Providing an explicit annotation for passing
by expression would standardise the semantics of these functions and,
as Michael suggests, would help static analysis. So passing by name
could be just another argument-passing method:

    function(expr@ x, value@ y = 10L, name@ z = rnorm(1)) {
      list(x, y, z, z)
    }

The parser would record the argument metadata in the formals list.
This metadata could be consulted by static analysis tools and a
selected subset of those tags (`expr` and `name`) would have an effect
on the evaluation mechanism.


RN> One thing I'm not clear on is whether the proposal would add anything
RN> semantically beyond what the present "eval" and "substitute" functions
RN> can do fairly easily.

Quasiquotation makes it possible to program with functions that take
arguments by expression. There is no easy way to do that with
eval() and substitute() alone. R has always been an interface language
and as such, its main advantage is to provide DSLs for data analysis
tasks. Specification of statistical models with a formula, overscoping
data frame columns with subset() and transform(), etc. This is why
providing an easier means of programming with these functions seems to
have more value than call-by-name semantics. Unquoting will be used
extensively in ggplot2 and dplyr, two popular R packages.  Please see
the vignette posted by Hadley for some introductory examples.

In any case, the unquoting notation would be orthogonal to function
arguments annotations because actuals and formals are parsed
differently. While formals annotations would be recorded by the parser
in the formals list, `@` in an actual argument list would be parsed as
a function call, like the rest of R operators.

Lionel



[Rd] RFC: (in-principle) native unquoting for standard evaluation
Lionel Henry