Skip to content

mget bugs out .SD #1744

Closed
Closed

Description

@franknarf1

Here's what I see in 1.9.7:

library(data.table)

DT = data.table(ID = 1:2, A = 3:4, B = 5:6)
DT[, mget("A"), .SDcols="B"]            # ok
DT[, c(list(A=A), .SD), .SDcols="B"]    # ok
DT[, c(mget("A"), .SD), .SDcols="B"]    # bonkers, see below

#    A ID A B x.ID x.A x.B
#1: 3  1 3 5    1   3   5
#2: 4  2 4 6    2   4   6

DT[, {
    myA = mget("A")
    names(.SD)
}]

# "ID"   "A"    "B"    "x.ID" "x.A"  "x.B" 

It looks like .SD becomes strange after mget is called. This looks related to #994 which was addressed in 1.9.6 according to the NEWS.

Activity

  1. added this to the v1.9.8 milestone on Jul 20, 2016
  2. eantonya commented on Oct 21, 2016

    @eantonya
    Contributor

    I don't think this is fully fixed:

    dt = data.table(a = 1, b = 2, c = 3)
    
    dt[, {list(a, get('b')); names(.SD)}, .SDcols = 'c']
    #[1] "a" "c"
  3. modified the milestones: , v1.9.8 on Nov 18, 2016
  4. MichaelChirico commented on Dec 21, 2016

    @MichaelChirico
    Member
    DT[, c(mget("A"), .SD), .SDcols="B", verbose = TRUE]
    

    '(m)get' found in j. ansvars being set to all columns. Use .SDcols or a single j=eval(macro) instead. Both will detect the columns used which is important for efficiency.
    Old: B
    New: ID,A,B

    #    A B
    # 1: 3 5
    # 2: 4 6
    

    So I guess the key is that the step where mget causes ansvars to be set to all columns is ignoring that .SDcols is actually specified. At a minimum, the warning message in verbose is incorrect.

  5. removed this from the milestone on May 10, 2018
  6. added this to the 1.12.4 milestone on Aug 28, 2019
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

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions