Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.A41.4.44.0306010835510.101876-100000@homer07.u.washington.edu>
Date: 2003-06-01T15:42:20Z
From: Thomas Lumley
Subject: parse on left hand side of R assignment
In-Reply-To: <3ED8DEEB.5090808@ku.edu>

On Sat, 31 May 2003, Paul E. Johnson wrote:

> I keep finding myself in a situation where I want to calculate a
> variable name and then use it on the left hand side of an assignment.
> For example
>
> iteration <- 1
> varName <- paste("run",iteration,sep="")
> myList$parse(text=varName) <- aColumn
>

In this particular case you can just use

myList[[varName]]<-aColumn.

I don't think you can (easily) use assign, despite the suggestion -- it
doesn't dispatch assignment methods.

If you wanted to do something of this sort for which the above didn't work
you could also learn about substitute()
  eval(substitute(myList$newColumn<-aColumn),
     list(newColumn=as.name(varName)))
as an alternative to parse().

	-thomas