From peter.meilstrup at gmail.com  Thu Jan  4 01:18:15 2018
From: peter.meilstrup at gmail.com (Peter Meilstrup)
Date: Wed, 3 Jan 2018 16:18:15 -0800
Subject: [Rd] Coping with non-standard evaluation in R program analysis
In-Reply-To: <DM5PR02MB2860748944E8E439755AB2EAA7190@DM5PR02MB2860.namprd02.prod.outlook.com>
References: <DM5PR02MB2860748944E8E439755AB2EAA7190@DM5PR02MB2860.namprd02.prod.outlook.com>
Message-ID: <CAJoaRhYbJjNU3EW+uCMeMObtosv+hgCf_BkrS+joLLXFShPVtw@mail.gmail.com>

For 2), it is not exposed in R's standard library but it is exposed in
the Rinternals API. A promise that is forced in normal evaluation will
have PRENV set to NULL.

Peter

On Tue, Jan 2, 2018 at 4:19 PM, Evan James Patterson
<epatters at stanford.edu> wrote:
> Hello R experts,
>
>
> I plan to develop a tool for dynamic analysis of R programs. I would like to trace function calls at runtime, capturing argument and return values. Following a suggestion made some time ago on this list, my high-level implementation strategy is to rewrite the AST, augmenting call expressions with pre-call and post-call shims to capture the arguments and return value, respectively.
>
>
> I can think of only one fundamental conceptual obstacle to this approach: R functions are not necessarily referentially transparent. The arguments received by a function are not values but promises. They can be evaluated directly ("standard evaluation"), after applying arbitrary syntactic transformations ("non-standard evaluation", aka NSE), or not at all. Therefore, if you peek at the values of function arguments before evaluating the function, you risk altering the semantics of the program, possibly fatally.
>
>
> I'm looking for general advice about how to cope with NSE in this context. I also have some specific questions:
>
>
> 1) Is it possible to determine whether a given function (primitive, in R, or external) uses NSE on some or all of its arguments?
>
>
> 2) Is it possible to inspect the promise objects received by functions, say to determine whether they have been evaluated, without actually evaluating them? The R manual is not encouraging in this area:
>
>
> https://cran.r-project.org/doc/manuals/r-release/R-lang.html#Promise-objects
>
>
> Thank you,
>
>
> Evan
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Coping with non-standard evaluation in R program analysis
Peter Meilstrup