Entering edit mode
Why does one fail but the other succeeds?
> DataFrame(ID = LETTERS[1:3], score = list(2:4, 6, 7:8))
Error in DataFrame(ID = LETTERS[1:3], score = list(2:4, 6, 7:8)) :
cannot coerce class "list" to a DataFrame
> data <- DataFrame(ID = LETTERS[1:3])
> data$score <- list(2:4, 6, 7:8)
> data
DataFrame with 3 rows and 2 columns
ID score
<character> <list>
1 A 2,3,4
2 B 6
3 C 7,8
Out of interest,
SimpleList()
works withoutI()
, why is that?Same reason that
list
works withoutI
. Bothdata.frame
andDFrame
objects have an expectation that the resulting object should have equal numbers of rows. Alist
orSimpleList
can contain anything in each list item.SimpleList is a List derivative and List derivatives in general don't need protection. For example, a GRangesList object (which is also a List derivative) does not need protection either:
Oh, ok. I understand. Technically both should work according to what the help page for
DataFrame
says (bothSimpleList
andlist
have[
andlength
functions and respect drop = FALSE). I don't know about the technicalities of the implementation, so maybe Herve will provide details.