Skip to content
Prev 277827 / 398506 Next

Introducing \n's so that par.strip.text can produce multiline strips in lattice

On Nov 18, 2011, at 1:51 AM, Ashim Kapoor wrote:

            
Of course there is. The key however ti to realize that at the moment  
there are "\\"'s and "n"'s but not any single characters with the  
representation "\n" when printed to the console.

If you are going to attempt to replace the "\\"'s with sub or gsub you  
need to futher realize that in order to match the "\\"'s in the  
current vactor you will need to further escape the "|" characters in  
the regex pattern

 > var
[1] "ee\\nee"
 > nchar(var)
[1] 6
 > grep("n", var)
[1] 1               # so there are ordinary "n" in there
 > grep("\\\\", var)
[1] 1               # and you need to use quadruple escapes (actually
                       escape-1 to generate an escape and escape-2 to  
match the escaped-\


imports$Indicator <- sub("\\\\n", "\n", imports$Indicator)
 > imports
                                            Indicator    Units  
Expression time       X03 id
1.7                            Gold & silver imports Rs.crore        
Ival    7  66170.46  1
2.7                                     Gold imports Rs.crore        
Ival    7  65337.72  2
3.7         Chemicals and related\n products imports Rs.crore        
Ival    7  62669.86  3
4.7  Pearls precious &\n semiprecious stones imports Rs.crore        
Ival    7  33870.17  4
5.7         Metaliferrous ores & metal scrap imports Rs.crore        
Ival    7  36779.35  5
snipped further output

You need to work on learning to create minimal code.