tidyverse / tibble

A modern re-imagining of the data frame
https://tibble.tidyverse.org/
Other
671 stars 130 forks source link

Error in stopifnot(is.character(filename), length(filename) == 1L) : reached elapsed time limit #1566

Open catalamarti opened 10 months ago

catalamarti commented 10 months ago

Hi team, We've built some packages on top of tibble and the tidyverse and we are facing a weird error/warning. It is displayed as an error, but is does not prevent us to use the function. In fact the error does not appear in the reprex (see reprex and image) as I guess it is more a message than an error. The error message does not appear if we unclass or use a data.frame.

reprex:

myclassConstructor <- function(x) {
  class(x) <- "myclass"
  return(x)
}

`[[.myclass` <- function(x, name) {
  x_raw <- unclass(x)
  tbl <- x_raw[[name]]
  attr(tbl, "reference") <- x
  return(tbl)
}

myElement <- tibble::tibble(a = 1)

# warning
obj <- myclassConstructor(x = list("element" = myElement))

# no warning
obj <- myclassConstructor(x = list("element" = 1))

# no warning
obj <- myclassConstructor(x = list("element" = unclass(myElement)))

# no warning
obj <- myclassConstructor(x = list("element" = as.data.frame(myElement)))

Created on 2023-12-18 with reprex v2.0.2

image with the error: image

edward-burn commented 10 months ago

@catalamarti it seems the problem comes from this line https://github.com/tidyverse/tibble/blob/6f5c3af47657576eeefdba0ad15edab07fe3f028/R/str.R#L11 (if I bring the package locally and comment these lines out this warning/ error no longer appeared)

To fix in the case above we can add str.myclass to avoid hitting str.tbl_df

myclassConstructor <- function(x) {
  class(x) <- "myclass"
  return(x)
}

`[[.myclass` <- function(x, name) {
  x_raw <- unclass(x)
  tbl <- x_raw[[name]]
  attr(tbl, "reference") <- x
  return(tbl)
}

myElement <- tibble::tibble(a = 1)

# warning
for(i in 1:5){
obj <- myclassConstructor(x = list("element" = myElement))
}

str.myclass <- function(){
  print("no problems now")
}
# no warning
for(i in 1:5){
obj <- myclassConstructor(x = list("element" = myElement))
}

Created on 2023-12-19 with reprex v2.0.2

edward-burn commented 10 months ago

@krlmlr I´m not sure if this issue should be closed as is or if some input validation can be added to str.tbl_df (it took some digging to work out what was going on)?

TimTaylor commented 10 months ago

AFAICT - the issue is not triggered by str.tbl_df() per se (although it is hit) but utils:::str.default() so I don't think there's anything for {tibble} to do. The [[.myclass function is a little odd in that it is actually creating a larger object that contains a copy of the original input. This creates infinite recursion when utils:::str.default inspects it's elements using [[.

Your likely seeing the error message due to something your editor is running internally to inspect the code on screen. You can trigger it directly calling str().

If you do want [[.myclass to function in it's current form then you will need to provide your own str method as above.