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

Add function to word wrap long character vectors #37

Merged
merged 4 commits into from Jun 10, 2015

Conversation

jimhester
Copy link
Member

This functionality is very useful in plot legends for instance.

Not sure if there is any active development on this package, but I thought I would send the pull request anyway...

@BrianDiggs
Copy link
Contributor

What does this do that using base::strwrap does not? Or, if this does simplify use of existing base functions for specific purposes, why does it not use base::strwrap at its core rather than implementing its own word wrapping algorithm?

@jimhester
Copy link
Member Author

It does not do anything that base::strwrap does not, I just had no
knowledge of that function existing before right now! Thanks for letting
me know, sorry for wasting everyones time. It would help if there was some
consistency to naming of base functions, but alas that ship has sailed.

Thanks again

On Wed, Nov 6, 2013 at 2:51 PM, Brian Diggs notifications@github.comwrote:

What does this do that using base::strwrap does not? Or, if this does
simplify use of existing base functions for specific purposes, why does it
not use base::strwrap at its core rather than implementing its own word
wrapping algorithm?


Reply to this email directly or view it on GitHubhttps://github.com//pull/37#issuecomment-27907269
.

@BrianDiggs
Copy link
Contributor

Not knowing every function in R is quite forgivable :)

Inconsistency in naming of base functions and their arguments is past fixing (as you noted), but there are packages which give more consistent interfaces. In this case, the stringr package does that for string manipulation (and provides a str_wrap function which does much of the simplifications you might want for the wrap function you wrote).

In fact, you could write your wrap function as

wrap <- function(width) {
  function(x) str_wrap(x, width=width)
}

which passes all the test cases you gave.

I'm not recommending that as code to use in the package, though, because it introduces a dependency on the stringr package which doesn't currently exist. Your most recent approach gets the essence of what str_wrap does for you.

@hadley
Copy link
Member

hadley commented Jun 10, 2015

This seems like a reasonable addition. Can you please:

  1. Rebase/merge
  2. Add a bullet to news
  3. Use a longer name? I think wrap is a bit too general for this specific use

This functionality is very useful in plot legends for instance.
Wish I would have known about that function this morning!
@jimhester
Copy link
Member Author

Ok 1c0ea8f should be good to go once the build finishes.

hadley added a commit that referenced this pull request Jun 10, 2015
Add function to word wrap long character vectors
@hadley hadley merged commit 0418281 into r-lib:master Jun 10, 2015
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 this pull request may close these issues.

None yet

3 participants