[R] pasting a formula string with double quotes in it

StellathePug ritacarreira at hotmail.com
Fri Apr 20 17:39:50 CEST 2012


Hello everyone,
I have tried several ways of doing this and searched the documentation and
help lists and I have been unable to find an answer or even whether it is
possible to do it. I am pasting together a formula and I need to insert
double quotes around the strings. Here's an example:

  location <- c("AL", "AK", "MA", "PA")
  v=2
  test <-  cbind(
               " <- cbind(df$DATE[df$LOCATION %in% c(",
               location[v], 
               ")], df$WTD.AVG.PRICE[df$LOCATION %in% c(",
               location[v],           
               ")])")
  
  test <- paste(test, collapse="")
  test
 
Solution:
[1] " <- cbind(df$DATE[df$LOCATION %in% c(AK)], df$WTD.AVG.PRICE[df$LOCATION
%in% c(AK)])"

This does not produce an error message but it is obviously wrong because I
need double quotes around AK, i.e.,
" <- cbind(df$DATE[df$LOCATION %in% c("AK")], df$WTD.AVG.PRICE[df$LOCATION
%in% c("AK")])"
And obviously, I gave R no indication whatsoever to use double quotes.


If I use 
 test <- paste(test, collapse=""") 
it does not work, which makes sense because the second double quote closes
the first and the third is left an orphan.

Anyone have any ideas?

Thanks and have a great weekend!
Rita


--
View this message in context: http://r.789695.n4.nabble.com/pasting-a-formula-string-with-double-quotes-in-it-tp4574419p4574419.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list