Alex Sanchez wrote:
Hello,
I would like to be able to compose an expression using some of the arguments I
give to a function, that is assuming I have a list such as:
my.list<-list(A=1:3,B=c("Brave", "new", "world"))
and a function
printComponent<-function(component){
if (component=="A"||component=="B"){
my.expression<-paste("my.list",component,sep="$")
print(my.expression)}
else{cat("Wrong argument, must be A or B")}
}
I would like that a call "printComponent("A")" to be equivalent to calling
my.list$A
It's much simpler! Use the [[ as in:
printComponent <- function(component){
my.list[[component]]
}
Uwe Ligges
[1] 1 2 3
but I only obtain
printComponent("A")
[1] "my.list$A"
I presume I must evaluate it somehow but I really can't find the instruction in
the manuals (I would also appreciate to know where should I have looked at)
Thanks for the help
----------------------------------------------------------
Dr. Alex S�nchez
Departament d'Estad�stica U.B.
Telf: 34 934021590
Fax: 34 93 4111733
e-mail : [EMAIL PROTECTED]
-----------------------------------------------------------
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html