cat(fill=N)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

cat(fill=N)

David Hugh-Jones-3
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

This is on R 3.4.3, but I don't see mentions of it fixed in 3.4.4 or
r-devel NEWS.

Cheers,
David

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat(fill=N)

Serguei Sokol
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.

Serguei.

>
> This is on R 3.4.3, but I don't see mentions of it fixed in 3.4.4 or
> r-devel NEWS.
>
> Cheers,
> David
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat(fill=N)

David Hugh-Jones-3
Agreed. Perhaps this is a documentation issue:

    fill: a logical or (positive) numeric controlling how the output is
          broken into successive lines.  If ‘FALSE’ (default), only
          newlines created explicitly by ‘"\n"’ are printed.
          Otherwise, the output is broken into lines with print width
          equal to the option ‘width’ if ‘fill’ is ‘TRUE’, or the value
          of ‘fill’ if this is numeric.  Non-positive ‘fill’ values are
          ignored, with a warning.

could add "Newlines are only printed between elements of x, not within
elements".

But I think the behaviour I expected is more intuitive. The natural use
case is to
limit line length, and if so, that should apply globally not just between
elements.


On 16 March 2018 at 16:19, Serguei Sokol <[hidden email]> 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.
>
> Serguei.
>
>
>> This is on R 3.4.3, but I don't see mentions of it fixed in 3.4.4 or
>> r-devel NEWS.
>>
>> Cheers,
>> David
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat(fill=N)

Berry, Charles
In reply to this post by Serguei Sokol


> On Mar 16, 2018, at 9:19 AM, Serguei Sokol <[hidden email]> 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
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel