[R] ASCII characters: from decimal code to R octal?

Henrik Bengtsson hb at maths.lth.se
Mon Feb 4 14:31:29 CET 2002


I was looking at the same problem/question last year (r-help May 09, 2001)
and what I ended up doing was what you suggests: a lookup table. See

   http://www.r-project.org/nocvs/mail/r-help/2001/2452.html

for a cut-n-paste complete solution, which I use myself.

I believe you could also to something like

octToChar <- function(octal) {
  code <- paste("\"\\", octal, "\"", sep="");
  eval(parse(text=code))
}

Except from fact that this example is not where robust ('octal' is
actually decimal), it is probably not very efficient.

Cheers

Henrik Bengtsson

Dept. of Mathematical Statistics @ Centre for Mathematical Sciences 
Lund Institute of Technology/Lund University, Sweden (+2h UTC)
Office: P316, +46 46 222 9611 (phone), +46 46 222 4623 (fax)
h b @ m a t h s . l t h . s e
http://www.maths.lth.se/matstat/staff/hb/



On Mon, 4 Feb 2002, David Firth wrote:

> Is there a straightforward way to convert character information from 
> decimal representation to the octal one used by R?
> 
> I'd like something like a function ascii(number,base=10), such that
> 
> >  ascii(91)
> [1] "\133"
> 
> I can easily do the mapping from 91 to 133, but what is a good way to 
> operate on  133 to deliver "\133"?
> 
> Would a lookup table be a better solution?
> 
> David
> -- 
> 
> 
> David Firth                        Phone +44 1865 278544
> Nuffield College                   Fax   +44 1865 278621
> Oxford OX1 1NF                     Secretary +44 1865 278553
> United Kingdom                     Email david.firth at nuffield.ox.ac.uk
> 
> http://www.stats.ox.ac.uk/~firth/
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list