Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call helper #4226

Merged
merged 7 commits into from
Feb 16, 2020
Merged

Call helper #4226

merged 7 commits into from
Feb 16, 2020

Conversation

MichaelChirico
Copy link
Member

@MichaelChirico MichaelChirico commented Feb 2, 2020

As we can see here, we have been using is.call(x) && x[[1L] == f-alike syntax a lot internally, and not always consistently.

This PR adds some helpers to

  1. Make the usage more consistent
  2. Make the code more concise/readable
  3. Centralize any fixes/improvements we think are needed eventually
  4. Begin to build a set of helpers for doing NSE stuff internally (hence started nse_utils.R instead of adding these in utils.R)

feedback welcome

@codecov
Copy link

codecov bot commented Feb 2, 2020

Codecov Report

Merging #4226 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4226      +/-   ##
==========================================
+ Coverage   99.61%   99.61%   +<.01%     
==========================================
  Files          73       72       -1     
  Lines       13884    13892       +8     
==========================================
+ Hits        13830    13838       +8     
  Misses         54       54
Impacted Files Coverage Δ
src/freadR.c 100% <100%> (ø) ⬆️
R/xts.R 100% <100%> (ø) ⬆️
R/data.table.R 100% <100%> (ø) ⬆️
src/chmatch.c 100% <100%> (ø) ⬆️
src/frank.c 100% <100%> (ø) ⬆️
R/fmelt.R 100% <100%> (ø) ⬆️
R/setkey.R 100% <100%> (ø) ⬆️
R/utils.R 100% <100%> (ø) ⬆️
R/between.R 100% <100%> (ø) ⬆️
R/fcast.R 100% <100%> (ø) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9f7b039...1cecbba. Read the comment docs.

Copy link
Member

@jangorecki jangorecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sub_in_funs is misleading, function is a valid output input in some cases like .SDcols, thus better name would be sub_in_calls @MichaelChirico name is misleading because it tests for function calls and not functions names

@MichaelChirico
Copy link
Member Author

function is a valid output in some cases like .SDcols

Sorry, not quite following, is this in reference to a specific place in the diff? or speaking more generally?

@MichaelChirico
Copy link
Member Author

Have made a small edit to chmatch.c to allow substitute(f(1, 2, 3))[[1L]] %chin% c('f', 'g') to work (no as.character necessary)

Would be interesting to know how SYMSXP == sym_lapply is working for #4174 so we could avoid the coercion to STRSXP, if possible.

src/chmatch.c Outdated
if (!isString(x) && !isNull(x)) {
// for use in sub_*_funs from nse_utils.R
if (TYPEOF(x) == SYMSXP) {
return chmatchMain(coerceVector(x, STRSXP), table, nomatch, chin, chmatchdup);
Copy link
Member Author

@MichaelChirico MichaelChirico Feb 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a PROTECT() here for the new coerceVector object?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need

@@ -1646,14 +1646,14 @@ replace_dot_alias = function(e) {
if (dotN(q)) return(TRUE) # For #5760
# run GForce for simple f(x) calls and f(x, na.rm = TRUE)-like calls where x is a column of .SD
# is.symbol() is for #1369, #1974 and #2949
if (!(is.call(q) && is.symbol(q[[1L]]) && is.symbol(q[[2L]]) && (q1c <- as.character(q[[1L]])) %chin% gfuns)) return(FALSE)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattdowle I believe here, note the comment about is.symbol

Copy link
Member

@mattdowle mattdowle Feb 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MichaelChirico Thanks. This is a convoluted one as it's inside !() so it's really (!is.call(q) || !is.symbol(q[[1L]])) && .... Haven't looked as the issues yet but it seems different use case than sub_is_fun. Btw, what about a name like is_call_to instead of sub_is_fun. The one function is_call_to(e, f) could accept length(f) 1 or >1 so we don't have to use sub_in_funs instead.

@jangorecki
Copy link
Member

Function is a valid input for .SDcols, so name is_fun corresponds to is.function really, while you use that name where we want to test if input is a call. It is better to have some long name than a confusing one.

@mattdowle mattdowle added this to the 1.12.9 milestone Feb 16, 2020
@mattdowle
Copy link
Member

mattdowle commented Feb 16, 2020

Great idea. This does simplify many internal lines very nicely and avoids expression repetition to reduce risk. I just simplified it down to one %iscall% function, and avoided the coerce of symbol to character by using PRINTNAME using a trick.
See what you think. I like it.

@mattdowle
Copy link
Member

mattdowle commented Feb 16, 2020

Maybe the new file in future then. FWIW, I'm not a fan of the NSE name. The term "non-standard" makes it sound non-desirable to me (since everyone seems these days to want to do what everyone else does; the standard). I always thought of it as delayed or lazy evaluation, as opposed to eager evaluation, and one of the great things about R.

@mattdowle mattdowle merged commit 44e20ba into master Feb 16, 2020
@mattdowle mattdowle deleted the call_helper branch February 16, 2020 08:46
@jangorecki jangorecki modified the milestones: 1.12.11, 1.12.9 May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants