Skip to content

treeshap.model_unified fails with data.table input #36

Description

@Balaika

In treeshap.model_unified function, this line does not behave as expected if x is a data.table :

x <- x[,colnames(x) %in% unified_model$feature_names]

x=data.table(a=1:3,b=2:4)
x[,colnames(x)%in%colnames(x)]
[1] TRUE TRUE
x%>%as.data.frame%>%.[,colnames(x)%in%colnames(x)]
  a b
1 1 2
2 2 3
3 3 4

I suggest to convert x to a data.frame when x is a data.table

Activity

  1. changed the title [-]treeshap.model_unified format checking fails with data.table[/-] [+]treeshap.model_unified fails with data.table input[/+] on Feb 29, 2024
  2. mayer79 commented on Apr 24, 2026

    @mayer79
    Contributor

    You seem to ask how to select columns in {data.table}.

    I can help you with this:

    library(data.table)
    
    x <- data.table(a = 1:3, b = 2:4)
    x[, colnames(x) %in% colnames(x), with = FALSE]

    Since the question seems completely unrelated to {treeshap}, I am closing the issue.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions