Bug 15369 - deparse cannot handle raw vectors
Summary: deparse cannot handle raw vectors
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Low-level (show other bugs)
Version: R 3.0.1
Hardware: All All
: P5 minor
Assignee: R-core
URL:
Depends on:
Blocks:
 
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.