[Rd] subRaw?

Spencer Graves spencer.graves at structuremonitoring.com
Fri Jul 20 05:29:38 CEST 2012


Hello, All:


       Do you know of any capability to substitute more then one byte in 
an object of class Raw?


       Consider the following:


 > let4 <- paste(letters[1:4], collapse='')
 > (let4Raw <- charToRaw(let4))
[1] 61 62 63 64
 > (let. <- sub('bc', '--', let4Raw))
[1] "61" "62" "63" "64"
 > # no substitution
 > (bc <- charToRaw('bc'))
[1] 62 63
 > (ef <- charToRaw('ef'))
[1] 65 66
 > (let. <- sub(bc, ef, let4Raw))
[1] "61" "65" "63" "64"
Warning messages:
1: In sub(bc, ef, let4Raw) :
   argument 'pattern' has length > 1 and only the first element will be used
2: In sub(bc, ef, let4Raw) :
   argument 'replacement' has length > 1 and only the first element will 
be used


       In this example, "b" was replaced by "e", but "bc" was not 
replaced by "ef"?  Do you know of any function to do this?


       I ask, because I need it.  I've written such a function, subRaw 
for my own use.  If I don't hear that another exists, I plan to add the 
one I've written to the oro.dicom package.


       Thanks,
       Spencer


 > sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods base

-- 
Spencer Graves, PE, PhD
President and Chief Technology Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567
web:  www.structuremonitoring.com



More information about the R-devel mailing list