Skip to content
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

consistent treatment of nested lists in replacement #6732

Open
tdhock opened this issue Jan 18, 2025 · 0 comments
Open

consistent treatment of nested lists in replacement #6732

tdhock opened this issue Jan 18, 2025 · 0 comments

Comments

@tdhock
Copy link
Member

tdhock commented Jan 18, 2025

since #6167 we have

> DT1=data.table(L=list("A"),i=1)
> DT1$L=list(list(list(NULL)));str(DT1)
Classesdata.tableand 'data.frame':	1 obs. of  2 variables:
 $ L:List of 1
  ..$ :List of 1
  .. ..$ : NULL
 $ i: num 1
 - attr(*, ".internal.selfref")=<externalptr> 
> DT1$L=list(list(NULL));str(DT1)
Classesdata.tableand 'data.frame':	1 obs. of  2 variables:
 $ L:List of 1
  ..$ : NULL
 $ i: num 1
 - attr(*, ".internal.selfref")=<externalptr> 
> DT1$L=list(NULL);str(DT1)
Classesdata.tableand 'data.frame':	1 obs. of  2 variables:
 $ L:List of 1
  ..$ : NULL
 $ i: num 1
 - attr(*, ".internal.selfref")=<externalptr> 
> DT1$L=NULL;str(DT1)
Classesdata.tableand 'data.frame':	1 obs. of  1 variable:
 $ i: num 1
 - attr(*, ".internal.selfref")=<externalptr> 

interpretation:

  • three nested list with NULL in code gives two nested lists in data.
  • one and two nested lists with NULL in code gives one list in data.

this is a weird edge case, that probably nobody will ever use, but it may be surprising to some users that list(list(NULL)) and list(NULL) give the same result, I would have expected that list(list(NULL)) results in two nested lists in the data, but to get that you actually have to use three lists in the code.

for reference, before #6167 we have similar behavior:

> DT1=data.table(L=list("A"),i=1)
> DT1$L=list(list(list(NULL)));str(DT1)
Classesdata.tableand 'data.frame':	1 obs. of  2 variables:
 $ L:List of 1
  ..$ :List of 1
  .. ..$ : NULL
 $ i: num 1
 - attr(*, ".internal.selfref")=<externalptr> 
> DT1$L=list(list(NULL));str(DT1)
Classesdata.tableand 'data.frame':	1 obs. of  2 variables:
 $ L:List of 1
  ..$ : NULL
 $ i: num 1
 - attr(*, ".internal.selfref")=<externalptr> 
> DT1$L=list(NULL);str(DT1)
Classesdata.tableand 'data.frame':	1 obs. of  1 variable:
 $ i: num 1
 - attr(*, ".internal.selfref")=<externalptr> 

summary table

RHS before #6167 after #6167
list(NULL) delete column list(NULL)
list(list(NULL)) list(NULL) list(NULL)
list(list(list(NULL))) list(list(NULL)) list(list(NULL))

so actually I'm not sure if we should even do anything about this... what do you think @MichaelChirico @joshhwuu ?
feel free to close if you think it is too useless / obscure / annoying.... haha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant