Skip to content

reallocate recursively in copy#4206

Merged
mattdowle merged 2 commits intomasterfrom
copy-nested-lists
Feb 17, 2020
Merged

reallocate recursively in copy#4206
mattdowle merged 2 commits intomasterfrom
copy-nested-lists

Conversation

@d-sci
Copy link
Copy Markdown
Contributor

@d-sci d-sci commented Jan 29, 2020

Closes #4205 (my apologies, I just re-read the contrib guidelines and had clearly forgotten about this part:)

"If you are not fixing an open issue and you are confident, you do not need to file a new issue before submitting the PR. It's easier for us to accept and merge a self-contained PR with everything in one place."

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 29, 2020

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4206      +/-   ##
==========================================
+ Coverage   99.61%   99.61%   +<.01%     
==========================================
  Files          72       72              
  Lines       13869    13909      +40     
==========================================
+ Hits        13815    13855      +40     
  Misses         54       54
Impacted Files Coverage Δ
R/merge.R 100% <ø> (ø) ⬆️
src/subset.c 100% <ø> (ø) ⬆️
R/as.data.table.R 100% <ø> (ø) ⬆️
src/assign.c 100% <ø> (ø) ⬆️
R/xts.R 100% <100%> (ø) ⬆️
src/fifelse.c 100% <100%> (ø) ⬆️
R/IDateTime.R 100% <100%> (ø) ⬆️
src/fwriteR.c 100% <100%> (ø) ⬆️
src/dogroups.c 100% <100%> (ø) ⬆️
R/setkey.R 100% <100%> (ø) ⬆️
... and 14 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 ddbb74b...31bdab1. Read the comment docs.

Comment thread R/data.table.R
.Call(C_unlock, y)
setalloccol(y)
} else if (is.list(y)) {
y[] = lapply(y, reallocate)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What happens if you have something like list(data.table(), list(list(list())))?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

eventually it either runs into an is.data.table branch or by default just does nothing right?

Comment thread R/data.table.R
if (is.data.table(y)) {
.Call(C_unlock, y)
setalloccol(y)
} else if (is.list(y)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess is.recursive would be more appropriate here? IIUC it would apply to anything for which the lapply(y, reallocate) part would go through

Copy link
Copy Markdown
Member

@mattdowle mattdowle Feb 17, 2020

Choose a reason for hiding this comment

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

Good thinking, but is.recursive is, unlike its name suggests, more like !is.atomic. For example, is.recursive(mean) is true! Feels right to me to use a direct is.list to target what's in mind, and postpone an expansion to is.recurisve until we know we need to and have an example and test.

Copy link
Copy Markdown
Member

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!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

?is.recursive does 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.

Copy link
Copy Markdown
Member

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:

/* is.recursive */
	switch(TYPEOF(CAR(args))) {
	case VECSXP:
	case LISTSXP:
	case CLOSXP:
	case ENVSXP:
	case PROMSXP:
	case LANGSXP:
	case SPECIALSXP:
	case BUILTINSXP:
	case DOTSXP:
	case ANYSXP:
	case EXPRSXP:
	// Not recursive, as long as not subsettable (on the R level)
	// case EXTPTRSXP:
	// case BCODESXP:
	// case WEAKREFSXP:
	    LOGICAL0(ans)[0] = 1;
	    break;
	default:
	    LOGICAL0(ans)[0] = 0;
	    break;
	}

@mattdowle mattdowle added this to the 1.12.9 milestone Feb 17, 2020
@mattdowle mattdowle changed the title reallocate recursively in copy, fixes #4205 reallocate recursively in copy Feb 17, 2020
@mattdowle mattdowle merged commit bfe23a4 into master Feb 17, 2020
@mattdowle mattdowle deleted the copy-nested-lists branch February 17, 2020 23:22
@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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

copy does not overallocate nested lists of data.tables

5 participants