RConsortium / S7

S7: a new OO system for R
https://rconsortium.github.io/S7
Other
387 stars 33 forks source link

Document Need to Define Classes in Order #325

Open jonthegeek opened 1 year ago

jonthegeek commented 1 year ago

This is somewhat discussed in #250 (in particular here), but before fully solving that issue it feels like it would be helpful to point out that a class needs to be defined earlier in a script or package if you want to use it as a property in another class. This is particularly confusing in a package context, so perhaps add it to the packages vignette?

# Causes the package to fail to build.
s7_parent <- S7::new_class(
  "s7_parent",
  package = "newS7fanciness",
  properties = list(name = s7_child)
)
#> Error in eval(expr, envir, enclos): object 's7_child' not found

s7_child <- S7::new_class(
  "s7_child",
  package = "newS7fanciness",
  properties = list(x = S7::class_character)
)

Created on 2023-08-25 with reprex v2.0.2

# Works
s7_child <- S7::new_class(
  "s7_child",
  package = "newS7fanciness",
  properties = list(x = S7::class_character)
)

s7_parent <- S7::new_class(
  "s7_parent",
  package = "newS7fanciness",
  properties = list(name = s7_child)
)

Created on 2023-08-25 with reprex v2.0.2