[Rd] cat(fill=N)

Berry, Charles ccberry at ucsd.edu
Fri Mar 16 18:13:43 CET 2018



> On Mar 16, 2018, at 9:19 AM, Serguei Sokol <sokol at insa-toulouse.fr> wrote:
> 
> Le 16/03/2018 à 17:10, David Hugh-Jones a écrit :
>> Hi all,
>> 
>> I expect I'm getting something wrong, but
>> 
>> cat("foo bar baz foo bar baz foo bar baz", fill = 10)
>> 
>> should be broken into lines of width 10, whereas I get:
>> 
>>> cat("foo bar baz foo bar baz foo bar baz", fill = 10)
>> foo bar baz foo bar baz foo bar baz
> On the other side, if I do
> > cat(strsplit("foo bar baz foo bar baz foo bar baz", " ")[[1]], fill = 10)
> I get the expected result:
> 
> foo bar
> baz foo
> bar baz
> foo bar
> baz
> 
> Which suggest that cat() doesn't break elements of submitted character vector
> put put enough of them to fill the requested width.

Also, see ?strwrap, which honors word boundaries

> cat(strwrap("foo bar baz foo bar baz foo bar baz", width = 10),fill=10)
foo bar 
baz foo 
bar baz 
foo bar 
baz
> 

HTH,

Chuck


More information about the R-devel mailing list