subset.data.table fails under NextMethod()

Open
#5,191 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
data

Research direction

Reproduce the example from the issue, then inspect R/data.table.R around line 2300 to trace how subset.data.table resolves the subset argument when called through NextMethod(). Compare the observed behavior with direct subset() calls and document the expected result; completion should include a verified fix and regression coverage for this example.

Written by the indexing model from the issue text.

Description

bug

I am not sure if this is just some puzzling behavior of S3, but it strikes me as incorrect:

x = as.data.table(mtcars)
class(x) = c("foo", class(x))

subset.foo = function(x, subset, select, ...) NextMethod("subset")

subset(x, mpg > 20)
# Error in subset.data.table(x, mpg > 20) : 
#   'subset' must evaluate to logical

It appears here:

https://github.com/Rdatatable/data.table/blob/8f0afcb44827f1df3ed231b87fda7768db047537/R/data.table.R#L2300

subset doesn't resolve to mpg > 20, but instead to the generic function subset.

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.