[R] Printing "pretty' vectors in Sweave

Joshua Wiley jwiley.psych at gmail.com
Wed Jan 19 07:27:54 CET 2011


Hi Robin,

Have you looked at the 'collapse' argument to paste?
something like:

myvec <- paste(1:4, collapse = ", ")

Might do what you want.  Also maybe ?bquote or the like to get rid of quotes possibly (I'm not in a position to try presently).

Side note, it is really probably best not to use 'c' as a variable name since it is such a fundamental function.

Cheers,

Josh


On Jan 18, 2011, at 21:46, Robin Jeffries <rjeffries at ucla.edu> wrote:

> I am trying to print a nice looking vector in Sweave.
> 
> c <- 1:4
> 
> I want to see (1, 2, 3, 4) in TeX. .
> 
> If I use
> paste(c, ",", sep="")
> I get
> "1," "2," "3," "4,"
> 
> If use cat(c, sep=",")
> I can't seem to assign it to an object,
> 1,2,3,4> myvec <- cat(c, sep=",")
> 1,2,3,4> myvec
> NULL
> 
> and if I bypass the object assignment and put
> "My vector is (\Sweave{cat(c, sep=",")}). "
> prints out
> "My vector is (). "
> 
> Suggestions?
> 
> 
> Robin Jeffries
> MS, DrPH Candidate
> Department of Biostatistics
> UCLA
> 530-624-0428
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.



More information about the R-help mailing list