[Rd] str(..., strict.width="wrap") changes alignment of colons

From: G See <gsee000_at_gmail.com>
Date: Wed, 28 Nov 2012 12:49:43 -0600


Hi,

This was surprising to me and does not appear to be documented in ?str. After reading ?strwrap, I see that the problem is that "Whitespace ... in the input is destroyed". However, I thought I'd mention it because I'm not sure it is intended behavior for str().

I have a list, and the names of the list have a variable number of characters.

> x <- list(A=1:10, ABCDEF=LETTERS[1:10])
> str(x)

List of 2
 $ A : int [1:10] 1 2 3 4 5 6 7 8 9 10  $ ABCDEF: chr [1:10] "A" "B" "C" "D" ...

The above looks as expected in my R session (although it looks a little different when I paste it into this e-mail). There are 5 spaces between the A and the colon. i.e. there are the same number of characters before the colon for both components of the list.

However, if I use strict.width="wrap", the colons (:) are no longer aligned

> str(x, width=20, strict.width='wrap')
List of 2
$ A : int [1:10] 1

   2 3 4 5 6 7 8 9
   10
$ ABCDEF: chr

   [1:10] "A" "B"
   "C" "D" ...

Notice that now there is only 1 space between the A and the colon instead of 5.

It looks like the call to strwrap() is causing the issue (i.e. destroying whitespace as it is documented to do).

This is fine:

> cat(capture.output(utils:::str.default(x)), sep="\n")
List of 2
 $ A : int [1:10] 1 2 3 4 5 6 7 8 9 10  $ ABCDEF: chr [1:10] "A" "B" "C" "D" ...

This isn't:

> cat(strwrap(capture.output(utils:::str.default(x)), 20), sep="\n")
List of 2
$ A : int [1:10] 1
2 3 4 5 6 7 8 9 10
$ ABCDEF: chr
[1:10] "A" "B" "C"
"D" ...

I'm wondering if it would be possible for the call to strwrap() to not include `indent.str`, `comp.str`, or the component names; then those things could be added afterwards. Although, I guess that probably requires adding an argument to str.default to control whether names are printed or not.

Regards,
Garrett



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 28 Nov 2012 - 18:52:55 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 28 Nov 2012 - 21:51:58 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive