[R] Pasting with Quotes

R. Michael Weylandt michael.weylandt at gmail.com
Sat May 5 20:50:39 CEST 2012


What's the "big picture" of what you're trying to do? eval(parse(text
= )) is often a less than optimal idea.

Some guesses:

Are you trying to construct a formula object (in the strict sense of
something that you pass to a modeling function)?

Maybe lazy evaluation of the deparse(substitute(x)) flavor might help here?

Michael

On Sat, May 5, 2012 at 2:42 PM, Josh Browning
<rockclimber112358 at gmail.com> wrote:
> Hello useRs!
>
> So, I have a random question.  I'm trying to build a character string, then
> evaluate it.  I think an example would be the easiest way to explain:
>
>
>    kern.vec = c("rbfdot","polydot")
>    for( j in 1:length( kern.vec ) )
>    {
>      formula    = paste("ksvm( ind ~ . ,
> data=d.temp[,c(ind_col,dep_cols)], kernel =",kern.vec[j],", prob.model=T )")
>      svm    = eval( parse( text=formula ) )
>     ...
>    }
>
>
> The problem I always seem to have is that in the formula, I need to have
> quotes around "rbfdot" (for example).  But, when I paste the expression
> together, it removes the quotes.  Is there a better way to do this (or at
> least a way around this problem)?  My method seems a bit kludgy :)
>
> Thanks for all your help!
>
> Josh
>
>        [[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