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 when spawning an object #63

Closed
cosi1 opened this issue May 4, 2021 · 3 comments
Closed

Error when spawning an object #63

cosi1 opened this issue May 4, 2021 · 3 comments

Comments

@cosi1
Copy link

cosi1 commented May 4, 2021

Reproducible example:

Annotated7 <- R7::new_class("Annotated7",
  properties = list(
    metadata = "list"
  )
)
setClassUnion("DataFrame_OR_NULL7", "NULL")

Vector7 <- R7::new_class("Vector7",
  parent = Annotated7,
  properties = list(
    elementMetadata = "DataFrame_OR_NULL7"
  )
)
v <- Vector7()

# Error in do.call(base::`@`, list(object, name)) :
#   trying to get slot "parent" from an object of a basic class ("character") with no slots

A brief investigation revealed that when the parent constructor (constructor of Annotated7)
is run from the constructor of Vector7, it incorrectly interprets object_class(sys.function(-1))
as "function" (a character string) instead of an R7 class, and tries to access a slot of that string.
(The problem doesn't occur when the constructor of Annotated7 is executed directly.)
sys.function(-1) seems to be the culprit.

@hadley
Copy link
Member

hadley commented Oct 22, 2021

Possibly related to #72.

@hadley
Copy link
Member

hadley commented Jan 18, 2022

Revisit after #134 is merged.

@hadley
Copy link
Member

hadley commented Jan 27, 2022

With #134

library(R7)

Annotated7 <- new_class("Annotated7", properties = list(metadata = "list"))

union <- setClassUnion("DataFrame_OR_NULL7", "NULL")

Vector7 <- R7::new_class("Vector7",
  parent = Annotated7,
  properties = list(
    elementMetadata = union
  )
)
Vector7(metadata = list(), elementMetadata = NULL)
#> Error: <Vector7>@elementMetadata must be of class <DataFrame_OR_NULL7>, not NULL

Created on 2022-01-26 by the reprex package (v2.0.1)

So this is just #72 + #139

@hadley hadley closed this as completed Jan 27, 2022
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