[R] Reading JPEG file, converting to HEX
Dennis Fisher
fisher at plessthan.com
Sun May 16 17:13:25 CEST 2010
Colleagues,
I am using R to assemble RTF documents (which are plain text). I need to embed a JPEG graphic that was created with R. I presume that the steps need to be:
a. read the file into R
b. convert the object to HEX format
c. write the converted object to a textfile.
If I read the file into R using readLines, I get the following (only the first 5 lines shown):
> > readLines("/path/to/file")
> [1] "\xff\xd8\xff\xe0"
> [2] "\002\xa3\003\001\""
> [3] "\v\xff\xc4"
> [4] "\026\027\030\031\032%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz\x83\x84\x85\x86\x87\x88\x89\x8a\x92\x93\x94\x95\x96\x97\x98\x99\x9a\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xff\xc4"
> [5] "\v\xff\xc4"
and I also receive a number of warning messages:
> Warning messages:
> 1: In encodeString(object, quote = "\"", na.encode = FALSE) :
> it is not known that wchar_t is Unicode on this platform
I assume (naively) that I need some other approach to reading the file. I also presume (again, naively) that once I have read the file successfully, I can convert the contents to hex format. However, it is not obvious to me what approach should be used to read the file. I found the command read.jpeg (in rimage; of note, I needed to use the Windows version because the OSX version appears to be broken). However, this command creates an "imagematrix", which does not appear to be what I need.
Any thoughts?
Thanks in advance.
Dennis
Dennis Fisher MD
P < (The "P Less Than" Company)
Phone: 1-866-PLessThan (1-866-753-7784)
Fax: 1-866-PLessThan (1-866-753-7784)
www.PLessThan.com
More information about the R-help
mailing list