-
Notifications
You must be signed in to change notification settings - Fork 1k
reallocate recursively in copy #4206
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -2345,21 +2345,18 @@ copy = function(x) { | |
| newx = .Call(Ccopy,x) # copies at length but R's duplicate() also copies truelength over. | ||
| # TO DO: inside Ccopy it could reset tl to 0 or length, but no matter as selfrefok detects it | ||
| # TO DO: revisit duplicate.c in R 3.0.3 and see where it's at | ||
| if (!is.data.table(x)) { | ||
| # fix for #1476. TODO: find if a cleaner fix is possible.. | ||
| if (is.list(x)) { | ||
| anydt = vapply_1b(x, is.data.table, use.names=FALSE) | ||
| if (sum(anydt)) { | ||
| newx[anydt] = lapply(newx[anydt], function(x) { | ||
| .Call(C_unlock, x) | ||
| setalloccol(x) | ||
| }) | ||
| } | ||
|
|
||
| reallocate = function(y) { | ||
| if (is.data.table(y)) { | ||
| .Call(C_unlock, y) | ||
| setalloccol(y) | ||
| } else if (is.list(y)) { | ||
| y[] = lapply(y, reallocate) | ||
|
Contributor
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. What happens if you have something like
Member
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. eventually it either runs into an |
||
| } | ||
| return(newx) # e.g. in as.data.table.list() the list is copied before changing to data.table | ||
| y | ||
| } | ||
| .Call(C_unlock, newx) | ||
| setalloccol(newx) | ||
|
|
||
| reallocate(newx) | ||
| } | ||
|
|
||
| .shallow = function(x, cols = NULL, retain.key = FALSE, unlock = FALSE) { | ||
|
|
||
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.
I guess
is.recursivewould be more appropriate here? IIUC it would apply to anything for which thelapply(y, reallocate)part would go throughUh oh!
There was an error while loading. Please reload this page.
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.
Good thinking, but
is.recursiveis, unlike its name suggests, more like!is.atomic. For example,is.recursive(mean)is true! Feels right to me to use a directis.listto target what's in mind, and postpone an expansion tois.recurisveuntil we know we need to and have an example and test.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.
good observation, I wish it was in the doc s!
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.
?is.recursivedoes include "Most types of objects are regarded as recursive. Exceptions are ..." but then I'm not really sure what it is useful for vs!is.atomic.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.
just happened upon the source for this as well: