Objective is to allow user to pass a string to a plotting function and have it evaluated correctly as plotmath
.
Question is how to combine an evaluated expression with other string text.
It seems the presence of any other string or expression nullifies the evaluation of the label.
Example:
label1 <- 'degree~C'
plot(1:10, type='l', xlab=bquote(.(parse(text=label1)))) #evaluated correctly
plot(1:10, type='l', xlab=bquote('Some text'~~Omega^2~~.(parse(text=label1)))) #missing degree C
Here is the output of the second plot showing that label1
is missing:
Expected output:
Other (possibly misguided) attempts:
plot(1:10, type='l', xlab=substitute(paste('Some text'~~Omega^2~~mystring), list(mystring=label1))) #string not evaluated
plot(1:10, type='l', xlab=substitute(paste('Some text'~~Omega^2~~mystring), list(mystring=parse(text=label1)))) #string missing entirely
plot(1:10, type='l', xlab=substitute(paste('Some text'~~Omega^2~~mystring), list(mystring=expression(text=label1)))) #string missing entirely