-
Notifications
You must be signed in to change notification settings - Fork 995
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
Refactor helper function issue #6702 (Refactored duplicated logic in setDT and [,:=]) #6752
base: master
Are you sure you want to change the base?
Changes from all commits
ef314b9
0be4b62
7bddf44
4e9bd73
97e1517
068474e
b23d277
581694a
76eb5bd
e12f726
cecfb0b
3592327
52f9d89
9ee7835
2e9835e
f554637
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: R Project CI/CD | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- setup-github-actions | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up R | ||
uses: r-lib/actions/setup-r@v2 | ||
with: | ||
r-version: devel | ||
|
||
- name: Install dependencies | ||
run: | | ||
install.packages("devtools") | ||
devtools::install_deps(dependencies = TRUE) | ||
|
||
- name: Run tests | ||
run: | | ||
R CMD check --as-cran |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert this change |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,13 @@ jobs: | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- uses: Anirban166/[email protected] | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: refactor-helper-function-issue-6702 | ||
- run: | | ||
echo "Current branch:" | ||
git branch | ||
echo "Listing all branches:" | ||
git branch -a | ||
- uses: Anirban166/[email protected] |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert this change |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,26 @@ methods::setPackageName("data.table",.global) | |
is.data.table = function(x) inherits(x, "data.table") | ||
is.ff = function(x) inherits(x, "ff") # define this in data.table so that we don't have to require(ff), but if user is using ff we'd like it to work | ||
|
||
# Helper function to process assignment operations in lists or environments. | ||
# Used internally for efficient recursive assignments in data.table. | ||
|
||
process_assignment <- function(name, x, parent_env) { | ||
k = eval(name[[2L]], parent_env, parent_env) | ||
if (is.list(k)) { | ||
origj = j = if (name[[1L]] == "$") as.character(name[[3L]]) else eval(name[[3L]], parent_env, parent_env) | ||
if (is.character(j)) { | ||
if (length(j) != 1L) | ||
stopf("Cannot assign to an under-allocated recursively indexed list -- L[[i]][,:=] syntax is only valid when i is length 1, but its length is %d", length(j)) | ||
j = match(j, names(k)) | ||
if (is.na(j)) | ||
stopf("Item '%s' not found in names of input list", origj) | ||
} | ||
.Call(Csetlistelt, k, as.integer(j), x) | ||
} else if (is.environment(k) && exists(as.character(name[[3L]]), k)) { | ||
assign(as.character(name[[3L]]), x, k, inherits = FALSE) | ||
} | ||
} | ||
|
||
#NCOL = function(x) { | ||
# # copied from base, but additionally covers data.table via is.list() | ||
# # because NCOL in base explicitly tests using is.data.frame() | ||
|
@@ -1214,22 +1234,9 @@ replace_dot_alias = function(e) { | |
setalloccol(x, n, verbose=verbose) # always assigns to calling scope; i.e. this scope | ||
if (is.name(name)) { | ||
assign(as.character(name),x,parent.frame(),inherits=TRUE) | ||
} else if (.is_simple_extraction(name)) { # TODO(#6702): use a helper here as the code is very similar to setDT(). | ||
k = eval(name[[2L]], parent.frame(), parent.frame()) | ||
if (is.list(k)) { | ||
origj = j = if (name[[1L]] == "$") as.character(name[[3L]]) else eval(name[[3L]], parent.frame(), parent.frame()) | ||
if (is.character(j)) { | ||
if (length(j)!=1L) stopf("Cannot assign to an under-allocated recursively indexed list -- L[[i]][,:=] syntax is only valid when i is length 1, but its length is %d", length(j)) | ||
j = match(j, names(k)) | ||
if (is.na(j)) internal_error("item '%s' not found in names of list", origj) # nocov | ||
} | ||
.Call(Csetlistelt,k,as.integer(j), x) | ||
} else if (is.environment(k) && exists(as.character(name[[3L]]), k)) { | ||
assign(as.character(name[[3L]]), x, k, inherits=FALSE) | ||
} else if (isS4(k)) { | ||
.Call(CsetS4elt, k, as.character(name[[3L]]), x) | ||
} | ||
} # TO DO: else if env$<- or list$<- | ||
} else if (name %iscall% c('$', '[[') && is.name(name[[2L]])) { | ||
process_assignment(name, x, parent.frame()) | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -2962,25 +2969,13 @@ setDT = function(x, keep.rownames=FALSE, key=NULL, check.names=FALSE) { | |
if (is.name(name)) { | ||
name = as.character(name) | ||
assign(name, x, parent.frame(), inherits=TRUE) | ||
} else if (.is_simple_extraction(name)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please be aware that the underlying code has changed since what was permalinked in #6702. In particular note this |
||
# common case is call from 'lapply()' | ||
k = eval(name[[2L]], parent.frame(), parent.frame()) | ||
if (is.list(k)) { | ||
origj = j = if (name[[1L]] == "$") as.character(name[[3L]]) else eval(name[[3L]], parent.frame(), parent.frame()) | ||
if (length(j) == 1L) { | ||
if (is.character(j)) { | ||
j = match(j, names(k)) | ||
if (is.na(j)) | ||
stopf("Item '%s' not found in names of input list", origj) | ||
} | ||
} | ||
.Call(Csetlistelt, k, as.integer(j), x) | ||
} else if (is.environment(k) && exists(as.character(name[[3L]]), k)) { | ||
assign(as.character(name[[3L]]), x, k, inherits=FALSE) | ||
} else if (isS4(k)) { | ||
} else if (name %iscall% c('$', '[[') && is.name(name[[2L]])) { | ||
process_assignment(name, x, parent.frame()) | ||
} | ||
else if (isS4(k)) { | ||
.Call(CsetS4elt, k, as.character(name[[3L]]), x) | ||
} | ||
} else if (name %iscall% "get") { # #6725 | ||
else if (name %iscall% "get") { # #6725 | ||
# edit 'get(nm, env)' call to be 'assign(nm, x, envir=env)' | ||
name = match.call(get, name) | ||
name[[1L]] = quote(assign) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this change is irrelevant |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3295,7 +3295,7 @@ test(1034, as.data.table(x<-as.character(sample(letters, 5))), data.table(V1=x)) | |
test(1035.291, melt(dt, measure.vars=NA_integer_, id.vars=NULL), error="One or more values in 'measure.vars'") | ||
test(1035.30, melt(dt, id.vars=NA_integer_), error="One or more values in 'id.vars'") | ||
test(1035.31, melt(dt, measure.vars=NA_character_), error="One or more values in 'measure.vars'") | ||
test(1035.32, melt(dt, id.vars=NA_character_), error="One or more values in 'id.vars'") | ||
test(1035.32, melt(dt, id.vars=NA_character_), error="One or more values in 'id.vars' is invalid.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert this change |
||
|
||
if (test_R.utils) { | ||
# dup names in variable used to generate malformed factor error and/or segfault, #1754; was test 1570 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert this change