Re: [R] Decoding subscripts/superscripts from CSVs

From: Jim Lemon <jim_at_bitwrit.com.au>
Date: Wed, 23 Jul 2008 22:00:18 +1000

On Tue, 2008-07-22 at 16:18 -0400, naw3_at_duke.edu wrote:
> Hi,
>
> I have a CSV file with various biological reactions. Subscripts, superscripts,
> and italics are encoded in carats, and I was wondering if R can actually
> recognize those and print actual superscripts, etc. Here's an example:
>
> <i>S</i>-adenosyl-L-methionine + rRNA = <i>S</i>-adenosyl-L-homocysteine +
> rRNA containing <i>N<sup>6</sup></i>-methyladenine
>
Hi Nina,
Embedded formatting commands enclosed in angle brackets (a caret is ^) are almost certainly from the SGML family of markup languages and probably from XML as this is becoming more common as a data format. If you want to translate the XML to plotmath, you must change the XML tags to plotmath tags. Here is a toy function for your example:

xml2pm<-function(xmlstring) {
 xmlstring<-gsub("<[iI]>","italic(",xmlstringE)
 xmlstring<-gsub("</[Ii]>",")",xmlstring)
 xmlstring<-gsub("<[Ss][Uu][Pp]>","^",xmlstring)
 xmlstring<-gsub("</[Ss][Uu][Pp]>","",xmlstring)
 return(xmlstring)
}

Jim



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 23 Jul 2008 - 12:57:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 23 Jul 2008 - 13:32:14 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive