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

Projects
None yet
3 participants
@jimhester
Member

jimhester commented Nov 6, 2013

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

This comment has been minimized.

Contributor

BrianDiggs commented Nov 6, 2013

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

This comment has been minimized.

Member

jimhester commented Nov 6, 2013

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

This comment has been minimized.

Contributor

BrianDiggs commented Nov 6, 2013

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

This comment has been minimized.

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

jimhester added some commits Nov 6, 2013

Add function to word wrap long character vectors
This functionality is very useful in plot legends for instance.
Use strwrap internally
Wish I would have known about that function this morning!

@jimhester jimhester force-pushed the jimhester:master branch from dba6822 to 1c0ea8f Jun 10, 2015

@jimhester

This comment has been minimized.

Member

jimhester commented Jun 10, 2015

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

hadley added a commit that referenced this pull request Jun 10, 2015

Merge pull request #37 from jimhester/master
Add function to word wrap long character vectors

@hadley hadley merged commit 0418281 into r-lib:master Jun 10, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment