Skip to content

accessing .SD via data.table::.SD gives NULL #2306

@spennihana

Description

@spennihana

I wasn't able to find an answer to this via searching SO/issues, so I'll just ask:

Is this legal way of accessing .SD:

someFun <- function(dt) {
  stopifnot(!is.null(dt))
  5
}

r <- data.table::data.table(iris)
r[ , someFun(data.table::.SD)    # Not OK
   , by=.(Sepal.Length)
 ]

# Error: !is.null(dt) is not TRUE

r[ , someFun(.SD)     # OK
   , by=.(Sepal.Length)
 ]

In someFun, the arg dt is NULL. Not a huge pain since I can do an explicit package import, but curious never-the-less.

edit: fixed up example

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