Just double all the backslashes and you are fine.
In order to see the outcome, use cat() (not print).

Uwe Ligges




On 16.06.2010 09:49, Stefan Petersson wrote:

Hi,

I'm trying to build a vector of latex commands. However, I need the command strings to 
begin with a backslash "\". I have:

test<- c('foo','bar')

and I need to rebuild the array, encapsulating the text items with latex stuff, 
like this:

paste("\parbox[b]{3cm}{", test, "}", fill=TRUE)

Actually, cat() prints the string fine if one uses double backslashes. However, 
I can't save the result from cat() back to a vector. And when I use cat() 
inside the latex function from the Hmisc package, I only get errors... The (not 
so) funny thing is that I can use paste() on a few latex commands. So if I 
needed to make the strings bold, the following works:

paste("\bfseries{", test, "}")

I've read the R FAQ 7.37, but it only deals with cat(). Not paste. Or I just 
didn't get it :o/

Is there a way to paste() the backslash character?

sessionInfo()
R version 2.11.1 (2010-05-31)
i486-pc-linux-gnu

locale:
  [1] LC_CTYPE=en_US.utf8       LC_NUMERIC=C
  [3] LC_TIME=en_US.utf8        LC_COLLATE=en_US.utf8
  [5] LC_MONETARY=C             LC_MESSAGES=en_US.utf8
  [7] LC_PAPER=en_US.utf8       LC_NAME=C
  [9] LC_ADDRESS=C              LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base


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

______________________________________________
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