various errors when RHS of := is closure/function
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Reproduce the closure assignments shown for one, two, and 101 rows, then inspect the := assignment and data.table print paths involved in the reported errors. Done should mean closure RHS values are handled consistently, with a clear error before malformed columns or inconsistent printing occur.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi! I encountered an error today (invalid type/length) which was informative enough for me to figure out and fix my issue (providing a closure/function on RHS of :=), but I wonder if we should recover more gracefully, for the benefit of newbies? In the code below we see that the assignment errors, and then there is a new column with value NULL, which causes a "malformed" error:
> myDT=data.table(x=1:101)
> myDT
x
<int>
1: 1
2: 2
3: 3
4: 4
5: 5
---
97: 97
98: 98
99: 99
100: 100
101: 101
> myDT[, y := data.table]
Error in `[.data.table`(myDT, , `:=`(y, data.table)) :
invalid type/length (closure/101) in vector allocation
> myDT
Error in `[.data.table`(x, i, , ) :
Column 2 is NULL; malformed data.table.
> str(myDT)
Classes 'data.table' and 'data.frame': 101 obs. of 2 variables:
$ x: int 1 2 3 4 5 6 7 8 9 10 ...
$ y: NULL
- attr(*, ".internal.selfref")=<externalptr>
This malformed error message does not happen when there are fewer rows, because the more complex print logic is not called, see below:
> myDT2=data.table(x=1:2)
> myDT2[, y := data.table]
Error in `[.data.table`(myDT2, , `:=`(y, data.table)) :
invalid type/length (closure/2) in vector allocation
> myDT2
x y
<int> <NULL>
1: 1 NULL
2: 2 NULL
When there is 1 row, the assignment succeeds (actually assigning the closure/function rather than NULL), but the print errors, see below:
> myDT1=data.table(x=1)
> myDT1[, y := data.table]
> myDT1
Error in dimnames(x) <- dn :
length of 'dimnames' [1] not equal to array extent
> str(myDT1)
Classes 'data.table' and 'data.frame': 1 obs. of 2 variables:
$ x: num 1
$ y:function (..., keep.rownames = FALSE, check.names = FALSE, key = NULL, stringsAsFactors = FALSE)
- attr(*, ".internal.selfref")=<externalptr>
Overall I would have expected more consistent and user-friendly behavior from := -- before assigning a new column (with value NULL or otherwise) would be great to stop early with an error message like "RHS of := is closure, which is almost certainly a mistake. If you really want to store a function in a data table, then please put it in a list column"
- Lingua principale
- R
- Stelle
- 3.9k
- Fork
- 1.1k
- Merge medio
- 14h 4m
- PR unite (30g)
- 4
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Rdatatable/data.table
-
as.data.table() recurses without end on a survival::Surv object (or any data.frame carrying one) Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
Rdatatable/data.table#7887 ·
-
consistency tests
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Rdatatable/data.table#7853 · 3 commenti ·
-
internals
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
Rdatatable/data.table#6938 · 1 commento ·
-
encoding fread
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
Rdatatable/data.table#5179 · 8 commenti ·
-
documentation programming
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Rdatatable/data.table#3199 · 3 commenti ·
Tutte le issue di Rdatatable/data.table
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
r-lib/pkgdepends#485 · 3 commenti ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
-
beginners blocker
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
enviPathR ApertaBuild Error Build OK Build Warning policies-accepted pre-review precheck-passed
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
Bioconductor/BiocContributions#207 · 6 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
datacarpentry/semester-biology#1255 ·