[R] how to make a function recognize the name of an object/vector given as argument

Wolfgang Raffelsberger wraff at igbmc.fr
Thu Sep 24 14:17:31 CEST 2009


Dear guRus,
I'd like to learn how to make a function recognize the name of an 
object/vector given as argument

If I have :

testFun <- function(x,y) plot(x,y, main=paste("plot 
of",names(x),"and",names(y)) )   # this just a simple example ...
a1 <- 5:8
b1 <- 9:6

testFun(a1,b1)
# Returns the plot, but not the names of the objects/vectors given as 
arguments,
# but since 'names()' refers to the elements INSIDE the object/vector I 
don't get what I'm looking for ...
# In fact, I (also) would like to know that actually "a1" and "b1" were 
given as arguments to my function.
# As in the example, this could be useful for (sub-)titles of graphs etc...
# Is there a way to get this kind of information ?

#For compleness:
 > sessionInfo()
R version 2.9.1 (2009-06-26)
i386-pc-mingw32

locale:
LC_COLLATE=French_France.1252;LC_CTYPE=French_France.1252;LC_MONETARY=French_France.1252;LC_NUMERIC=C;LC_TIME=French_France.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

Thank's in advance,
Wolfgang

 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Wolfgang Raffelsberger, PhD
Laboratoire de BioInformatique et Génomique Intégratives
CNRS UMR7104, IGBMC,  
1 rue Laurent Fries,  67404 Illkirch  Strasbourg,  France
Tel (+33) 388 65 3300         Fax (+33) 388 65 3276
wolfgang.raffelsberger (at) igbmc.fr




More information about the R-help mailing list