Skip to content

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

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

Activity

  1. MichaelChirico commented on Mar 12, 2025

    @MichaelChirico
    Member

    I think in this case we can continue the kludge pretty easily -- there's already logic for get(), it was just written before get0() existed (? or at least was more well-known):

    } else if (name %iscall% "get") { # #6725

    Note also #6702

  2. venom1204 commented on Mar 13, 2025

    @venom1204
    Contributor

    Hi @MichaelChirico @rikivillalba

    Can I work on this issue .
    As suggested by Michael, I'll update the existing logic in setDT() to handle get0() similarly to get():

    else if (name %iscall% c("get", "get0"))
    

    Is this approach working good or is there anything else you would like to suggest?
    Thanks!

  3. MichaelChirico commented on Mar 14, 2025

    @MichaelChirico
    Member

    Let's get #6802 finished first, since it is likely to generate conflict with that change

  4. venom1204 commented on Jun 24, 2025

    @venom1204
    Contributor

    hi @MichaelChirico now as the issue #6702 is finished can i work on this issue
    i have proposed solution for it.
    thanks for your time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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