镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

"Can't assign to the same column twice in the same query" message unhelpful, and inconsistent #2967

Open

Description

@MichaelChirico
DT = data.table(a = 1:5)
DT[ , c('b', 'b') := 10]
# Error in `[.data.table`(DT, , `:=`(c("b", "b"), 10)) : 
#   Can't assign to the same column twice in the same query (duplicates detected).

In more dynamic situations, this error is rather unhelpful.

Error happens here at the C level:

if (any_duplicated(cols,FALSE)) error("Can't assign to the same column twice in the same query (duplicates detected).");

any_duplicated is part of the R C API, the second argument is from_last.

Probably OK to jump to using something with Duplicated within the if (any_duplicated(cols, FALSE)) branch.


What's more, this error doesn't occur if the assignment takes place with by:

DT[ , c('b', 'b') := 10, by = a]
#    a  b
# 1: 1 10
# 2: 2 10
# 3: 3 10
# 4: 4 10
# 5: 5 10

Activity

  1. changed the title [-]"Can't assign to the same column twice in the same query" message unhelpful[/-] [+]"Can't assign to the same column twice in the same query" message unhelpful, and inconsistent[/+] on Jul 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions