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

Format method vs. print method #145

Open
jennybc opened this issue Jun 7, 2023 · 2 comments
Open

Format method vs. print method #145

jennybc opened this issue Jun 7, 2023 · 2 comments
Labels

Comments

@jennybc
Copy link
Member

jennybc commented Jun 7, 2023

I think it would be good to write up what belongs in a format method vs. a print method. Mostly conveying that, when in doubt, put the smarts in the format method and do as little as possible in print.

Possible secondary question: should you implement a str() method? What's the difference between format/print and str?

@jennybc
Copy link
Member Author

jennybc commented Jun 7, 2023

A good (anti) example is how hard it is to capture the printed "look" of a data.frame. Basically you have to use capture.output().

@hadley
Copy link
Member

hadley commented Jun 7, 2023

If you do write a format method, should it return a single string, or a character vector with one element per line?

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

No branches or pull requests

2 participants