delpacho wrote:
Hi everybody,

my goal is to display symbols on the x-axis of a barplot.
I read some mathematics strings in a file and convert them to an expression
as follows:

tt<- scan(file = fstr ,'what' ='character', sep = "");

for (iaa in 1:length(tt)) { tt[iaa]<-do.call(expression, lapply(tt[iaa], as.name));
}

I obtained the following result:

tt =

expression(`alpha[tr]`, beta, widthD, `S[ts]^-5("[165,275]Hz")`, `S[ts]^2("[165,275]Hz")`, `S[ts]^-5("[275,460]Hz")`, `S[r]^2("[165,275]Hz")`, `S[r]^-5("[275,460]Hz")`, `S[r]^3("[100,165]Hz")`, `T[ts]^4("[165,275]Hz")`, `T[ts]^7("[21,30]Hz")`, `T[ts]^8("[13,21]Hz")`, `T[r]^7("[21,30]Hz")`, `T[r]^8("[13,21]Hz")`, `T[r]^9("[8,13]Hz")`, `E("[100,165]Hz")`, `E("[165,275]Hz")`, `E("[60,100]Hz")`, `E("[8,13]Hz")`, `E("[30,60]Hz")`, `E("[21,30]Hz")`)

only the strings without "`" are interpreted properly when I put the
property names.arg =tt in barplot (ex:beta displays the greek letter,
whereas `alpha[tr]` displays alpha[tr]), could you explain me why these
symbol "`" intervenes when I convert the strings to an expression and/or how can I have the symbols associated with the strings displayed properly?

You used as.name() to convert the strings to expressions, so it converted them to names. You really want to parse them, not just convert them to names. For example,

> tt <- c("alpha[tr]", "beta", "S[ts]^-5(\"[165,275]Hz\")")
> barplot(1:3, names.arg=parse(text=tt))

Duncan Murdoch

______________________________________________
R-help@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.

Reply via email to