-
Notifications
You must be signed in to change notification settings - Fork 1k
programming on data.table #4304
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
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
5b8f98b
working draft of substitute names
jangorecki 838f00d
substitute2 draft
jangorecki a2b876b
add example from #2655
jangorecki 994ce4a
! on scalar not vector
MichaelChirico 7816631
handle AsIs so char and symbols can be both used in env arg
jangorecki 6084f28
non-symbol handling
jangorecki 472d6d6
data.table query env support, rm AsIs class from env input
jangorecki 8167ef2
manual and tests
jangorecki fd44346
tests roadmap
jangorecki 247ed7a
export substitute2 and is.AsIs, minor manual improvements
jangorecki 048e370
move and improve tests
jangorecki d60152d
manual typo
jangorecki fed2553
simplifies API, export less
jangorecki fd5582e
rework inner loop, tests, docs
jangorecki c1fbdfb
tests
jangorecki ffb97d4
man wording
jangorecki e6f2203
minor tests adjustments
jangorecki 507e253
add use cases contributed by @renkun-ken
jangorecki e99ae00
solve known issues about get
jangorecki 9e61025
improve test for renkun-ken use case
jangorecki b498263
minor fix for proper scoping
jangorecki b0094f7
more tests addressing existing issues
jangorecki 9878dbf
add use case by #@tdeenes
jangorecki 57514ed
missing env
jangorecki 4c1001d
env test and man
jangorecki 24f4a07
fix test num reference
jangorecki 783f3a9
news entry and minor doc changes
jangorecki 9a31604
test can now test itself
jangorecki 5d34753
enlist, recursive enlisting
jangorecki 28e240f
programming on data.table vignette
jangorecki d056afe
NEWS wording
jangorecki a42e3d2
fix rmd yaml index entry
jangorecki 5c47c09
typos and wording
jangorecki e869026
empty input to substitute2
jangorecki 09e0499
empty input to env more robust
jangorecki 0ebef14
Merge branch 'master' into programming
jangorecki 73ca1ca
Merge branch 'master' into programming
mattdowle c67d75f
move news item up
mattdowle d00f292
merge follow-up to pass programming.Rraw
mattdowle 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
| ^.*\.Rproj$ | ||
| ^\.Rproj\.user$ | ||
| ^\.idea$ | ||
| ^\.libs$ | ||
|
|
||
| ^.*\.dll$ | ||
|
|
||
|
|
||
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,80 @@ | ||
| is.AsIs = function(x) { | ||
| inherits(x, "AsIs") | ||
| } | ||
| rm.AsIs = function(x) { | ||
| cl = oldClass(x) | ||
| oldClass(x) = cl[cl!="AsIs"] | ||
| x | ||
| } | ||
| list2lang = function(x) { | ||
| if (!is.list(x)) | ||
| stop("'x' must be a list") | ||
| if (is.AsIs(x)) | ||
| return(rm.AsIs(x)) | ||
| asis = vapply(x, is.AsIs, FALSE) | ||
| char = vapply(x, is.character, FALSE) | ||
| to.name = !asis & char | ||
| if (any(to.name)) { ## turns "my_name" character scalar into `my_name` symbol, for convenience | ||
| if (any(non.scalar.char <- vapply(x[to.name], length, 0L)!=1L)) { | ||
| stop("Character objects provided in the input are not scalar objects, if you need them as character vector rather than a name, then wrap each into 'I' call: ", | ||
| paste(names(non.scalar.char)[non.scalar.char], collapse=", ")) | ||
| } | ||
| x[to.name] = lapply(x[to.name], as.name) | ||
| } | ||
| if (isTRUE(getOption("datatable.enlist", TRUE))) { ## recursively enlist for nested lists, see note section in substitute2 manual | ||
| islt = vapply(x, is.list, FALSE) | ||
| to.enlist = !asis & islt | ||
| if (any(to.enlist)) { | ||
| x[to.enlist] = lapply(x[to.enlist], enlist) | ||
| } | ||
| } | ||
| if (any(asis)) { | ||
| x[asis] = lapply(x[asis], rm.AsIs) | ||
| } | ||
| x | ||
| } | ||
| enlist = function(x) { | ||
| if (!is.list(x)) | ||
| stop("'x' must be a list") | ||
| if (is.AsIs(x)) | ||
| return(rm.AsIs(x)) | ||
| as.call(c(quote(list), list2lang(x))) | ||
| } | ||
|
|
||
| substitute2 = function(expr, env) { | ||
| if (missing(expr)) | ||
| return(substitute()) | ||
| if (missing(env)) { | ||
| stop("'env' must not be missing") | ||
| } else if (is.null(env)) { | ||
| # null is fine, will be escaped few lines below | ||
| } else if (is.environment(env)) { | ||
| env = as.list(env, all.names=TRUE, sorted=TRUE) | ||
| } else if (!is.list(env)) { | ||
| stop("'env' must be a list or an environment") | ||
| } | ||
| if (!length(env)) { | ||
| return(substitute(expr)) | ||
| } | ||
| env.names = names(env) | ||
| if (is.null(env.names)) { | ||
| stop("'env' argument does not have names") | ||
| } else if (!all(nzchar(env.names))) { | ||
| stop("'env' argument has zero char names") | ||
| } else if (anyNA(env.names)) { | ||
| stop("'env' argument has NA names") | ||
| } else if (anyDuplicated(env.names)) { | ||
| stop("'env' argument has duplicated names") | ||
| } | ||
| # character to name/symbol, and list to list call | ||
| env = list2lang(env) | ||
| # R substitute | ||
| expr.sub = eval(substitute( | ||
| substitute(.expr, env), | ||
| env = list(.expr = substitute(expr)) | ||
| )) | ||
| if (missing(expr.sub)) | ||
| return(substitute()) ## nested emptiness | ||
| # substitute call argument names | ||
| .Call(Csubstitute_call_arg_namesR, expr.sub, 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
Oops, something went wrong.
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.