From btyner at gmail.com  Thu Jan  4 05:09:24 2018
From: btyner at gmail.com (Benjamin Tyner)
Date: Wed, 3 Jan 2018 23:09:24 -0500
Subject: [Rd] Coping with non-standard evaluation in R program analysis
In-Reply-To: <mailman.5.1514977203.7011.r-devel@r-project.org>
References: <mailman.5.1514977203.7011.r-devel@r-project.org>
Message-ID: <d8dd49c6-517f-f372-bb4b-56a39e85f61c@gmail.com>

Evan,

The pryr package provides some utilities which may be handy here. In 
particular see the function: is_promise.

Also, next time please post in plaintext.

Regards
Ben
> 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]]
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> R-devel at r-project.org mailing list  DIGESTED
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
> ------------------------------
>
> End of R-devel Digest, Vol 179, Issue 1
> ***************************************



[Rd] Coping with non-standard evaluation in R program analysis
Benjamin Tyner