Column type overwrite fails for recycled values

Open
#2,577 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
r
Domain
data

Research direction

Reproduce the data.table(a = 1:2)[, a := 'b'] example and inspect the [.data.table entry point that emits the coercion warnings. The issue names no source file or test; first establish the intended behavior for recycled values, then verify the chosen behavior with a regression test.

Written by the indexing model from the issue text.

Description

bug
data.table(a = 1:2)[ , a := 'b']

Warning messages:
1: In [.data.table(data.table(a = 1:2), , :=(a, "b")) :
NAs introduced by coercion
2: In [.data.table(data.table(a = 1:2), , :=(a, "b")) :
Coerced 'character' RHS to 'integer' to match the column's type. Either change the target column ['a'] to 'character' first (by creating a new 'character' vector length 2 (nrows of entire table) and assign that; i.e. 'replace' column), or coerce RHS to 'integer' (e.g. 1L, NA_[real|integer]_, as.*, etc) to make your intent clear and for speed. Or, set the column type correctly up front when you create the table and stick to it, please.

Not sure if this is intended behavior... it's technically against the rule specified by the warning, but seems like a natural usage

Dominant language
R
Stars
3.9k
Forks
1.1k
Avg merge
14h 4m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rdatatable/data.table

All issues in Rdatatable/data.table

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.