Re: [R] print.raw - but convert ASCII?

From: Matt Shotwell <biostatmatt_at_gmail.com>
Date: Tue, 19 Apr 2011 09:10:51 -0500

On Tue, 2011-04-19 at 03:14 -0400, Duncan Murdoch wrote:
> On 11-04-18 9:51 PM, Matt Shotwell wrote:
> > Does anyone know if there is a simple way to print raw vectors, such
> > that ASCII characters are printed for bytes in the ASCII range, and
> > their hex representation otherwise? rawToChar doesn't work when we have
> > something like c(0x00, 0x00, 0x44, 0x00).
>
> Do you really need hex? rawToChar(x, multiple=TRUE) comes close, but
> displays using octal or symbolic escapes, e.g.

No, but I've almost learned to count efficiently in hex. :)

> [1] "" "\001" "\002" "\003" "\004" "\005" "\006" "\a" "\b"
> "\t" "\n"
> [12] "\v" "\f" "\r" "\016" "\017" "\020" "\021" "\022" "\023"
> "\024" "\025"
> [23] "\026" "\027" "\030" "\031" "\032" "\033" "\034" "\035" "\036"
> "\037" " "
> [34] "!" "\"" "#" "$" "%" "&" "'" "(" ")"
> "*" "+"
>
> If you really do want hex, then you'll need something like
>
> ifelse( x < 32 | x >= 127, as.character(x), rawToChar(x, multiple=TRUE))

That does it. Thanks. -Matt

> Duncan Murdoch



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 19 Apr 2011 - 14:38:21 GMT

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 Tue 19 Apr 2011 - 14:40:31 GMT.

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

list of date sections of archive