[R] Word-Wrapper Library/Package?

Leonard Mada |eo@m@d@ @end|ng |rom @yon|c@eu
Wed Sep 29 04:25:43 CEST 2021

Dear R-Users,

Does anyone know any package or library that implements functions for 
word wrapping?

I did implement a very rudimentary one (Github link below), but would 
like to avoid to reinvent the wheel. Considering that word-wrapping is a 
very common task, it should be available even in base R (e.g. in a 
"format" module/package).




The latest versions of the functions are on Github:

# Note:
# - the function implementing word wrapping: split.N.line(...);
# - for the example below: the functions defined in Tools.CRAN.R are 

### Search CRAN

searchCran = function(s, from=1, len=60, len.print=20, extend="*",
         sep=" ", sep.h="-") {
     if( ! is.null(extend)) s = paste0(s, extend);
     x = advanced_search(s, size=len, from=from);
     if(length(x$package_data) == 0) {
         cat("No packages found!", sep="\n");
     } else {
         scroll.pkg(x, len=len.print, sep=sep, sep.h=sep.h);

# with nice formatting & printing:
x = searchCran("text", from=60, sep.h="-")

scroll.pkg(x, start=20, len=21, sep.h = "-*")
# test of sep.h=NULL vs ...


1.) split.N.line:

- was implemented to output a pre-specified number of lines (kind of 
"maxLines"), but this is not required from an actual word-wrapper;

- it was an initial design decision when implementing the format.lines() 
function; but I plan to implement a 1-pass exact algorithm during the 
next few days anyway;

2.) Refactoring

- I will also move the formatting code to a new file: probably 

- the same applies for the formatting code for ftable (currently in file 

3.) Package gridtext

- seems to have some word-wrapping functionality, but does not seem to 
expose it;

- I am also currently focused on character-based word wrapping (e.g. for 

	[[alternative HTML version deleted]]

More information about the R-help mailing list