[Rd] Calling applyClosure from a package?

Matthew Kay m@tthew@k@y @end|ng |rom u@northwe@tern@edu
Sun Apr 14 21:21:52 CEST 2024


Hi,

Short version of my question: Rf_applyClosure was marked
attribute_hidden in Oct 2023, and I am curious why and if there is an
alternative interface to it planned.

Long version:

I have been toying with building a package that makes it easier to do
non-standard evaluation directly using promises, rather than wrapping
these in a custom type (like e.g. rlang does). The advantage of this
approach is that it should be fully compatible with functions that use
the standard R functions for NSE and inspecting function context, like
substitute(), match.call(), or parent.frame(). And indeed, it works!
-- in R 4.3, that is. The prototype version of the package is here:
https://github.com/mjskay/uneval  (the relevant function to my
question is probably do_invoke, in R/invoke.R).

While testing on R-devel, I noticed that Rf_applyClosure(), which used
to be exported, is now marked with attribute_hidden. I traced the
change to this commit in Oct 2023:
https://github.com/r-devel/r-svn/commit/57dbe8ad471c8a34314ee74362ad479db03c033a

However, the commit message did not give me clarity on the reason for
the change, and I have not been able to find mention of this change in
R-devel, R-package-devel, or the R bug tracker.
So, I am curious why this function is no longer exported and if there
is an alternative function planned to take its place.

Neither Rf_eval nor do.call can do what I need to fully support
rlang-style NSE using base R. The problem is that I need to be able to
manually set up the list of promises provided as arguments to the
function.

I fully understand that the answer to my question might be "don't do
that" ;). But I will humbly suggest that it would be really nice to be
able to do NSE that can capture expressions with heterogeneous
environments and pass these to functions in a way that is compatible
with existing R functions that do NSE. The basic tools to do it are
there in R 4.3, I think...

Thanks for the help!

---Matt

-- 
Matthew Kay
Associate Professor
Computer Science & Communication Studies
Northwestern University
matthew.kay using u.northwestern.edu
http://www.mjskay.com/



More information about the R-devel mailing list