Skip to content
Prev 23048 / 398502 Next

problem with toString

Thank you for your helpful answer. As far as I can understand, that means if I don't know how long my expression q is, I 
should use something as this:

 q <- expression(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19))
 d <- deparse(q)
 s=""
 for (i in 1:length(d))
 {
 	s <- paste(tmp, d[i])
 }
 substring(s, 13, nchar(s)-1)

(The superfluous spaces in string s don't bother me and can easily be removed.) Maybe one could use a shorter method 
using apply for this?

I'd like to add some additional information about the background answering the question why I need this: I am planning to 
write a kind of plugin of a GPL Computer Algebra System to R enabling it to calculate symbolically.

What I have done is to use unevaluated expressions as input to my symbolic functions. These expressions are converted to 
strings (therefore my question), the strings are syntactically converted and then piped to the CAS from which I get strings 
back. Those answer strings are then converted into R expressions again, returned by the function. For example:
expression(sqrt(3)/2)

There are still some problems doing it this way: Long integers and fractions are shortened during the conversion from string 
to R expression. If I get back 1000! as a string, R will make it to inf. But this is due to the fact that R has never been 
intended to do such work, I know... (I will use unconverted strings in such cases)
By the way, converting strings to R expressions I am using parse together with temporary files. Is there an easier way doing 
this without temp files?

All the same, my testing results are promising: Even although R has not been intended to calculate symbolically, many things 
seem to be implementable. And maybe I can make a package for R in the future containing the sources of the CAS, providing 
many essential symbolic functions - I think this could be of general interest.

Thanks once more for your help,

king regards,

Tobias Elze.


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._