-
Notifications
You must be signed in to change notification settings - Fork 42
Silently ignore missing arguments in constructor #446
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
Draft
t-kalinowski
wants to merge
6
commits into
main
Choose a base branch
from
constructor-skip-missing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2985a9d
add `collect_dots_skip_missing_`
t-kalinowski 57dabec
update tests
t-kalinowski 16cb422
Convert to snapshot tests.
t-kalinowski 8bdad50
Add tests for `list2()`
t-kalinowski 11aaf2d
Merge branch 'main' into constructor-skip-missing
t-kalinowski 438ae21
Updates after #445
t-kalinowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| #define R_NO_REMAP | ||
| #include <R.h> | ||
| #include <Rinternals.h> | ||
|
|
||
| SEXP collect_dots_skip_missing_(SEXP env, SEXP list_dddExprs_call) { | ||
| // This function is equivalent to `base::list(...)`, except it | ||
| // silently skips missing arguments. Ideally we could iterate | ||
| // over the DOTSXP list of promises directly, but there is currently | ||
| // no non-"non-API" way to do this. So we use `base::missing(..i)` to | ||
| // test for missingness, and use `substitute(list(...))` to get the | ||
| // promise expressions. | ||
| static SEXP missing_call = NULL; | ||
| if (missing_call == NULL) { | ||
| SEXP missing_fun = Rf_eval(Rf_install("missing"), R_BaseEnv); | ||
| missing_call = Rf_lang2(missing_fun, R_NilValue); | ||
| R_PreserveObject(missing_call); | ||
| } | ||
| // 14 = 2 for ".." + up to 10 digit number + '\0' + 1 extra for safety | ||
| static char ddi_buf[14] = ".."; | ||
| static char *i_buf = ddi_buf + 2; | ||
| ddi_buf[13] = '\0'; // Technically not necessary, but just to be safe | ||
|
|
||
| PROTECT_INDEX pi; | ||
| PROTECT_WITH_INDEX(R_NilValue, &pi); | ||
|
|
||
| { | ||
| unsigned int i = 1; | ||
| SEXP prev_node = list_dddExprs_call; | ||
| SEXP ddExpr_node = CDR(list_dddExprs_call); | ||
| for (; ddExpr_node != R_NilValue; i++) { | ||
| snprintf(i_buf, sizeof(ddi_buf) - 2, "%u", i); | ||
| SEXP ddSym = Rf_install(ddi_buf); | ||
| SETCADR(missing_call, ddSym); | ||
| SEXP is_missing = Rf_eval(missing_call, env); | ||
| REPROTECT(is_missing, pi); | ||
|
|
||
| if (Rf_asLogical(is_missing)) { | ||
| ddExpr_node = CDR(ddExpr_node); | ||
| SETCDR(prev_node, ddExpr_node); | ||
| } else { | ||
| if (TAG(ddExpr_node) == R_NilValue) { | ||
| SEXP val_expr = CAR(ddExpr_node); | ||
| if (TYPEOF(val_expr) == SYMSXP) { | ||
| SET_TAG(ddExpr_node, val_expr); | ||
| } | ||
| } | ||
| SETCAR(ddExpr_node, ddSym); | ||
| prev_node = ddExpr_node; | ||
| ddExpr_node = CDR(ddExpr_node); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| UNPROTECT(1); // is_missing | ||
| return Rf_eval(list_dddExprs_call, env); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.