Fix for #475

Replaces `structure(.)` with `setattr()` to set attributes by reference so that the over-allocation of `data.table` isn't lost.
Haven't used `testthat` before. Have added tests. Hope it's fine.