[R] Expression evaluation of Plotting labels containing spaces

David Winsemius dwinsemius at comcast.net
Wed Jun 5 06:13:50 CEST 2013


On Jun 4, 2013, at 8:39 PM, Santosh wrote:

> Dear Rxperts,
> How do I overcome the anomaly as in the second case of examples below?
>
> exc <- list(units=list( c(m^2)) ,vars= list(c('asb')), ,label=  
> list(c('abs
> surf body')))
>
> plot(1:10,1:10, ylab=parse(text= paste(exc$vars[1],'
> (',exc$units[1],')',sep='')))
>
> plot(1:10,1:10, ylab=parse(text= paste(exc$label[1],'
> (',exc$units[1],')',sep='')))

Mail client mangled this due entirely to your improper use HTML. You  
have been posting to Rhelp long enough to have had plenty of  
opportunity to read the Posting Guide. And I know for a fact that it  
is quite easy to send plain text using gmail. You have no legitimate  
excuse for continuing this deprecated practice.

Anyway,  running this code:

exc <- list(units=list( c("m^2")) ,vars= list(c('asb')), label=  
list(c('abs surf body')))
# Notice that I quoted the 'units' value
plot(1:10,1:10, ylab=parse(text= paste(exc$vars[1],'(',exc 
$units[1],')',sep='')))
# Also note that plotmath cannot handle embedded carriage returns
plot(1:10,1:10, ylab=parse(text= paste(exc$label[1],'(',exc 
$units[1],')',sep='')))

Produces this error:

Error in parse(text = paste(exc$label[1], "(", exc$units[1], ")", sep  
= "")) :
   <text>:1:5: unexpected symbol
1: abs surf
        ^
(You are asked in the Posting Guide exactly your code and also to post  
your error messages.)

So you are trying to parse an expression and the parser is expecting a  
comma or a tilde or  .... something other than the beginning of  
another token. You never said what you actually wanted (also a request  
in the Posting Guide),  but try adding tilde's:

exc <- list(units=list( c("m^2")) ,vars= list(c('asb')), label=  
list(c('abs~surf~body')))

plot(1:10,1:10, ylab=parse(text= paste(exc$vars[1],'(',exc 
$units[1],')',sep='')))

plot(1:10,1:10, ylab=parse(text= paste(exc$label[1],'(',exc 
$units[1],')',sep='')))

I know that the plotmath help page is not exactly the most expansive  
regarding how to form proper expressions for R but at least review it  
and run the examples:

?plotmath

-- 
David.

>
> Thanks so much!
>
> Santosh
>
> 	[[alternative HTML version deleted]]

Sigh.
>
>
> 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.


---
David Winsemius, MD
Alameda, CA, USA



More information about the R-help mailing list