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

Provide friendly_type? #463

Closed
hadley opened this issue May 5, 2022 · 3 comments · Fixed by #511
Closed

Provide friendly_type? #463

hadley opened this issue May 5, 2022 · 3 comments · Fixed by #511
Labels
feature a feature request or enhancement
Milestone

Comments

@hadley
Copy link
Member

hadley commented May 5, 2022

It'd be nice to be able to write:

abort("`{.arg levels} must be a character vector, not a {.friendly levels}")

And know that the user is going to get something that makes sense to them.

@gaborcsardi
Copy link
Member

gaborcsardi commented May 5, 2022

Re the implementation, in general {.class ...} only does styling and not other evaluation and it also does not have information about the frame where the error was thrown. But we could have functions that return some cli::cli_vec() objects, that have a desired style, after the appropriate processing. We could add a class argument to cli_vec() to make it easier to return a vector with a cli class.

So the syntax would be just a regular function call:

abort("`{.arg levels} must be a character vector, not a {friendly_type(levels)}")

These functions also do not need to live in cli, btw. For the generic ones it makes sense to live there, but I imagine that some of the would be specific to a package, etc.

@gaborcsardi gaborcsardi added the feature a feature request or enhancement label May 5, 2022
@hadley
Copy link
Member Author

hadley commented May 5, 2022

Oh yeah, this would be fine as a function too. I think this particular one belongs in cli because it's so needed in so many places.

@hadley
Copy link
Member Author

hadley commented May 12, 2022

Collection of places we've defined this before:

  • ggplot2:::obj_desc (and soon to be copied in to forcats)
  • rlang:::friendly_type_of
  • R7::obj_desc

Somewhat related is vec_ptype_full(), but it's a precise description of the type, not something designed to be user friendly.

I suspect we'll want at least two versions, one for scalars, and one for vectors.

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

Successfully merging a pull request may close this issue.

2 participants