Skip to content
Back to formatted view

Raw Message

Message-ID: <7406b4f80905150735k4c48d265tb42ca2d376a8bdc2@mail.gmail.com>
Date: 2009-05-15T14:35:17Z
From: Philipp Schmidt
Subject: creating and then executing command strings
In-Reply-To: <4A0D704F.1070604@dbmail.com>

On Fri, May 15, 2009 at 3:38 PM, Romain Francois
<romain.francois at dbmail.com> wrote:
> Hi,
>
> You can either parse and eval the string you are making, as in:
>
> eval( parse( text = paste("avg_",colname, " <- 0;", sep='') ) )
>
>
> Or you can do something like this:
>
> df[[ paste( "avg_", colname, sep = "" ) ]] <- 0
>

Thanks you so much! I used the first version and it worked.

What puzzles me, is that I am not able to use <- instead of = (my R
book says the two can be exchanged) or break the command into
different parts and execute them one after another.

I get various error messages when I try:

eval( parse( text <- paste("avg_",colname, " <- 0;", sep='') ) )

or

text = paste("avg_",colname, " <- 0;", sep='')
parse(text)
eval(parse(text))

Anyway, thanks a lot - you greatly improved the likelihood of me not
working on the weekend!

Best - P