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

Find the OO system used for an object #1426

Closed
hadley opened this issue Jun 19, 2022 · 2 comments · Fixed by #1428
Closed

Find the OO system used for an object #1426

hadley opened this issue Jun 19, 2022 · 2 comments · Fixed by #1428

Comments

@hadley
Copy link
Member

hadley commented Jun 19, 2022

Something like this:

obj_oo_type <- function(x) {
  if (is.object(x)) {
    if (inherits(x, "R7_object")) {
      "R7"
    } else if (inherits(x, "R6")) {
      "R6"
    } else if (isS4(x)) {
      "S4"
    } else {
      "S3"
    }
  } else {
    "base"
  }
}

This might possibly live in shim file, but that partly depends on the result of r-lib/cli#463 and r-lib/vctrs#139 — I think we need to host a consistent way of describing types somewhere centrally (either in rlang or maybe in a new package).

@lionel-
Copy link
Member

lionel- commented Jun 21, 2022

Maybe we should add this to compat-friendly-type.R?

@hadley
Copy link
Member Author

hadley commented Jun 21, 2022

Yeah, that's probably a reasonable place for now.

I can't quite figure if there's enough here for a separate package or not. When you consider the full scope of abbreviated vs full vs user facing type names, there is potentially a lot of code that we'd want to use in a lot of places.

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

Successfully merging a pull request may close this issue.

2 participants