Skip to content

setDT not always sets ".internal.selfref" #6864

@rikivillalba

Description

@rikivillalba

Reading #6862 I found this behaviour:

ds = copy(datasets::iris)
x = setDT(get("ds"))
attr(ds, ".internal.selfref")   # <pointer...>

ds = copy(datasets::iris)
x = setDT(get0("ds"))            # note get0
attr(ds, ".internal.selfref")    # NULL

Both ds's set as data.table's but in the second form, ds lacks selfref.
AFAIK setalloccol() is shallow copying ds, but then setDT fails to reassign it to the symbol ds because not recognizing 'get0' bindimg.
Arguably there is no easy way to detect the binding for every possible call that returns a data.table bound to a symbol, so I think setDT should warn when it is unable to assign it back -if a shallow copy is made-. or if ds lacks selfref before returning.
However, x does have it, and thus identical(ds, x) fails in second case.
Related perhaps #6754

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions