[R] get function to return object "name"?

Marianne Promberger mpromber at psych.upenn.edu
Wed Sep 2 18:30:56 CEST 2009


Dear list,

I've written a function that plots subjects. Something like:

myplot <- function(subject) { plot(subject) }

Subjects are vectors, e.g. ...
s1 <- c(200,200,190,180)
... and plotting them works fine, e.g. ... 
myplot(s1)

Now I want to have "s1" etc appear in the plot title, but I don't know
how to refer to this generically (the object "name"? I tried
as.name(s1) but that returns the first element of the vector).

So I want something like :

myplot <- function(subject) { plot(subject,main=X) }

where X is the expression I'm looking for, and the plot should have the title
"s1" if I've called myplot(s1), "s2" if myplot(s2), etc.

I'm sure I'll be really embarrassed that this is so trivial but I
cannot figure it out.


Marianne

-- 
Marianne Promberger PhD
King's College London




More information about the R-help mailing list