Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
catalamarti opened this issue Dec 18, 2023 · 3 comments

Comments

@catalamarti
Copy link

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
Copy link

@catalamarti it seems the problem comes from this line

tibble/R/str.R

Line 11 in 6f5c3af

utils::str(
(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
Copy link

@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
Copy link
Contributor

TimTaylor commented Dec 20, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants