Bug 15369 - deparse cannot handle raw vectors
deparse cannot handle raw vectors
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: Low-level
R 3.0.1
All All
: P5 minor
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-06-29 10:18 UTC by Olaf Mersmann
Modified: 2013-06-29 12:55 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olaf Mersmann 2013-06-29 10:18:54 UTC
When deparse()ing a raw vector, R returns an invalid expression

  > x <- as.raw(8:20)
  > deparse(x)
  [1] "c(08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 10, 11, 12, 13, 14)"

There are two problems with the returned value. First, it contains hexadecimal constants without the '0x' prefix and even if that is fixed, it returns a numeric vector and not a raw vector. I would have expect something along the lines of

  as.raw(c(0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14))

to be returned. 

The problem is also exhibited by dput and dump (likely because the use deparse() internally):

  > dput(x, "")
  c(08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 10, 11, 12, 13, 14)
  > dump("x", "")
  x <-
  c(08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 10, 11, 12, 13, 14)

str() also lacks the leading '0x' prefix when displaying raw vectors:

  > str(x)
   raw [1:13] 08 09 0a 0b ...

Note that setting control="all" when calling deparse() does not help:

  > deparse(x, control="all")
  [1] "c(08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 10, 11, 12, 13, 14)"
Comment 1 Duncan Murdoch 2013-06-29 12:55:04 UTC
Fixed in R-devel r63096 and soon in R-patched.