Skip to content

Infinite recursion in as.data.table() #6878

Description

@beckerbenj

Using as.data.table.data.frame() on a data.frame which inherits from another class leads to an infinite recursion. This seems to have been introduced in #6865 and also came up in #6874. The issue is caused in line 218 in as.data.table.R:

if (!identical(class(x), "data.frame")) return(as.data.table(as.data.frame(x), keep.rownames=keep.rownames, key=key, ...))

# Minimal reproducible example (not executed as this breaks reprex)

df1 <- data.frame(var1 = 1:10)
class(df1) <- c("data.frame", "someClass")
out <- data.table::as.data.table(df1)

Activity

  1. MichaelChirico commented on Mar 21, 2025

    @MichaelChirico
    Member

    as noted in #6874 I think this is the fault of a bug in your as.data.frame method. anyway this is a duplicate.

  2. beckerbenj commented on Mar 21, 2025

    @beckerbenj
    Author

    This was indirectly filed to me as a bug report by someone who uses one of my packages (which uses as.data.table()). I agree that this is their fault, but it still can be quite cumbersome to debug for packages using data.table especially as this simply leads to a C stack error.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions