Closed be-marc closed 4 years ago
a = data.table(y = list(0), opt_x = list(list(z_1 = 100, z_2 = 200))) unnest(a, "opt_x") # > x y z_1 z_2 # > 1: 1 0 0 0 a = data.table(z = list(0), opt_x = list(list(z_1 = 100, z_2 = 200))) unnest(a, "opt_x") # > x z z_1 z_2 # > 1: 1 0 100 200
The bug occurs when the unnested columns are added to the data.table with rcbind since y is used as the variable name for the unnested columns.
rcbind
y
rcbind function (x, y) { assert_data_table(x) assert_data_table(y) if (ncol(x) == 0L) { return(y) } if (ncol(y) == 0L) { return(x) } if (nrow(x) != nrow(y)) { stopf("Tables have different number of rows (x: %i, y: %i)", nrow(x), nrow(y)) } dup = intersect(names(x), names(y)) if (length(dup)) { stopf("Duplicated names: %s", str_collapse(dup)) } x[, `:=`(names(y), y)][] }
Thanks, should be fixed now.
The bug occurs when the unnested columns are added to the data.table with
rcbind
sincey
is used as the variable name for the unnested columns.