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

S3 Classes with format and print? #5

Open
krlmlr opened this issue Jun 11, 2015 · 5 comments
Open

S3 Classes with format and print? #5

krlmlr opened this issue Jun 11, 2015 · 5 comments
Labels
feature a feature request or enhancement

Comments

@krlmlr
Copy link
Member

krlmlr commented Jun 11, 2015

For instance:

dput(pretty_bytes(1000))
> structure(1000, class = "pretty_bytes")
print(pretty_bytes(1000))
> [1] "1 kB"

Would you support this kind of functionality? It might break compatibility, but then there are not many revdeps (yet) ;-)

krlmlr pushed a commit to krlmlr/ulimit that referenced this issue Jun 11, 2015
doesn't offer S3 dispatch yet, r-lib/prettyunits#5
@gaborcsardi
Copy link
Member

Yeah, that would be a more R-ish way, I guess. Which also means somewhat more messy of course. :)
E.g. if you do

x <- structure(1337, class = "pretty_bytes")
paste("File size:", x)

then no formatting is used. If we also implement as.character.pretty_bytes, then even this works, but it probably just messes up something else.

But we can do it, anyway, and then we'll see how it works out. :)

@krlmlr
Copy link
Member Author

krlmlr commented Jun 11, 2015

How important is backward compatibility? We could start by providing

pretty <- function(x, units) {
  structure(x, class = "pretty", units = units)
}

and deprecating the pretty_... stuff, just to reintroduce it in version 2.0.0. Or we break everything right away ;-)

@gaborcsardi
Copy link
Member

I would like to keep the current way as well. We can just add a pretty or maybe pretty_units class independently I think. The current way would be kept as it is, so nothing breaks. Yeah, no many revdeps on CRAN, but I do use it in a couple of packages, and I also like the current simple way.

@gaborcsardi
Copy link
Member

We probably want to use vctrs for this now?

@krlmlr
Copy link
Member Author

krlmlr commented Dec 27, 2019

I think subclassing "vctrs_vctr" will help us a lot here.

@gaborcsardi gaborcsardi added enhancement feature a feature request or enhancement and removed enhancement labels Oct 31, 2023
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

No branches or pull requests

2 participants