Skip to content

Commit

Permalink
Closes #936. Can re-assign/update factor cols by list type.
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsrinivasan committed Jan 28, 2015
1 parent c5ecd41 commit 41b749f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@

32. `rbindlist` stack imbalance on all `NULL` list elements is now fixed. Closes [#980](https://github.com/Rdatatable/data.table/issues/980). Thanks to @ttuggle.

33. List columns can be assigned to columns of `factor` type by reference. Closes [#936](https://github.com/Rdatatable/data.table/issues/936). Thanks to @richierocks for the minimal example.

#### NOTES

1. Clearer explanation of what `duplicated()` does (borrowed from base). Thanks to @matthieugomez for pointing out. Closes [#872](https://github.com/Rdatatable/data.table/issues/872).
Expand Down
4 changes: 4 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -5908,6 +5908,10 @@ test(1478.2, sapply(ll, length), INT(1,2,0,0))
test(1479, rbindlist(replicate(4,rbindlist(replicate(47, NULL),
use.names=TRUE, fill=TRUE)), use.names=TRUE, fill=TRUE), null.data.table())

# #936, assigning list column to a factor column by reference
DT <- data.table(x = factor(c("a", "b c", "d e f")))
test(1480, DT[, x := strsplit(as.character(x), " ")], data.table(x=list("a", letters[2:3], letters[4:6])))

##########################


Expand Down
2 changes: 1 addition & 1 deletion src/assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ SEXP assign(SEXP dt, SEXP rows, SEXP cols, SEXP newcolnames, SEXP values, SEXP v
if (isMatrix(thisvalue) && (j=INTEGER(getAttrib(thisvalue, R_DimSymbol))[1]) > 1) // matrix passes above (considered atomic vector)
warning("%d column matrix RHS of := will be treated as one vector", j);
if ((coln+1)<=oldncol && isFactor(VECTOR_ELT(dt,coln)) &&
!isString(thisvalue) && TYPEOF(thisvalue)!=INTSXP && !isReal(thisvalue)) // !=INTSXP includes factor
!isString(thisvalue) && TYPEOF(thisvalue)!=INTSXP && !isReal(thisvalue) && !isNewList(thisvalue)) // !=INTSXP includes factor
error("Can't assign to column '%s' (type 'factor') a value of type '%s' (not character, factor, integer or numeric)", CHAR(STRING_ELT(names,coln)),type2char(TYPEOF(thisvalue)));
if (nrow>0) {
if (vlen>targetlen)
Expand Down

0 comments on commit 41b749f

Please sign in to comment.