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

walkAST() gives error with S7 object. #93

Closed
egenn opened this issue Jan 22, 2025 · 5 comments
Closed

walkAST() gives error with S7 object. #93

egenn opened this issue Jan 22, 2025 · 5 comments
Milestone

Comments

@egenn
Copy link

egenn commented Jan 22, 2025

Hi - This is similar to #28, #27, but with S7 objects.
Passing an S7 object to a future.apply::future_lapply() call throws error
Error: Cannot walk expression. Unknown object type ‘object’.
Runs with future.globals = FALSE.

Create S7 object:

> Dat <- S7::new_class(
+   name = "Dat",
+   properties = list(
+     value = S7::class_numeric
+   )
+ )
> obj <- Dat(value = 1.2)

Minimal example:

> future.apply::future_lapply(1L, function(i, x) class(x), x = obj)
Error: Cannot walk expression. Unknown object type ‘object’
10: stop(msg, call. = FALSE)
9: walkAST(expr[[cc]], atomic = atomic, name = name, call = call,
       pairlist = pairlist, substitute = FALSE)
8: walkAST(expr, call = tweakFutureAssignmentCall)
7: tweak(expr)
6: findGlobals(expr, envir = envir, ..., method = method, tweak = tweak,
       substitute = FALSE, unlist = unlist)
5: globalsOf(expr, envir = envir, substitute = FALSE, tweak = tweak,
       locals = locals, dotdotdot = "return", method = globals.method,
       unlist = TRUE, mustExist = mustExist, recursive = TRUE)
4: getGlobalsAndPackages(expr, envir = envir, globals = globals)
3: getGlobalsAndPackagesXApply(FUN = FUN, args = args, MoreArgs = MoreArgs,
       envir = envir, future.globals = future.globals, future.packages = future.packages,
       debug = debug)
2: future_xapply(FUN = FUN, nX = nX, chunk_args = X, args = list(...),
       get_chunk = `chunkWith[[`, expr = expr, envir = envir, future.envir = future.envir,
       future.globals = future.globals, future.packages = future.packages,
       future.scheduling = future.scheduling, future.chunk.size = future.chunk.size,
       future.stdout = future.stdout, future.conditions = future.conditions,
       future.seed = future.seed, future.label = future.label, fcn_name = fcn_name,
       args_name = args_name, debug = debug)
1: future.apply::future_lapply(1L, function(idx, x) class(x), x = obj)

Works with globals disabled:

> future.apply::future_lapply(1L, function(i, x) class(x), x = obj, future.globals = FALSE)
[[1]]
[1] "Dat"       "S7_object"
@egenn egenn changed the title BUG: walkAST() gives error with S7 object. walkAST() gives error with S7 object. Jan 22, 2025
@HenrikBengtsson HenrikBengtsson added this to the Next release milestone Jan 22, 2025
@HenrikBengtsson
Copy link
Collaborator

HenrikBengtsson commented Jan 22, 2025

Thanks. I think a minimal reproducible example of this is:

A <- S7::new_class(name = "A")
obj <- A()
globals::walkAST(obj, call = identity)
#> Error: Cannot walk expression. Unknown object type 'object'

@HenrikBengtsson
Copy link
Collaborator

HenrikBengtsson commented Jan 22, 2025

I actually found a smaller example:

obj <- S7::S7_object()
globals::walkAST(obj, call = identity)
#> Error: Cannot walk expression. Unknown object type 'object'

@egenn
Copy link
Author

egenn commented Jan 22, 2025

globals::walkAST(S7::S7_object())
#> Error: Cannot walk expression. Unknown object type ‘object’

@HenrikBengtsson
Copy link
Collaborator

Got a minimal reproducible example that doesn't bring in non-base-R packages thanks to RConsortium/S7#524 (comment);

> obj <- asS3(methods::getClass("S4")@prototype, complete = FALSE)
> globals::walkAST(obj)
Error: Cannot walk expression. Unknown object type 'object'

Now I can add this as a unit test, and then fix it.

@HenrikBengtsson
Copy link
Collaborator

This has been fixed in the next release, e.g.

> globals::walkAST(S7::S7_object())
<S7_object>

Until submitted to CRAN, it's available as:

remotes::install_github("futureverse/globals", ref = "develop")

Thanks for reporting.

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

2 participants