[R] problem with toString

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Fri Aug 30 08:51:10 CEST 2002


Why are you using toString?  The main purpose of toString is to
get truncate the character representation of objects: otherwise
as.character would suffice.

The problem you are seeing is in as.character:

> as.character(q2)
[1] "c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, "

and it comes from the cutoff value of 60 in deparse.  I would use

tmp <- deparse(q2, 500)
substring(tmp, 12, nchar(tmp)-1)


On Fri, 30 Aug 2002, Tobias Elze wrote:

> Hi,
>
> I am using R 1.5.1 under Windows 2000. I have a problem with the
function toString: It seems not to work for longer
> vectors as expressions.
>
> This example works well:
>
> q1<-expression(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15))
> toString(q1)
>
> I get:
> "c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)"  => OK
>
>
> But this one does not:
> q2<-expression(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19))
> toString(q2)
>
> I get:
> "c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, "  => WRONG
>
> R cuts my vectors if they are too long. Can someone help me about this?
>
> Thank you,
>
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

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



More information about the R-help mailing list