I would like to write a function in R that would take a variable number of integers as parameters. I do not have a pressing reason to do this, I am just trying to learn R. I thought a good first step would be to print out the arguments. So I wrote the following function:

f1 = function (...)
{
    list1 = as.list(...)
    for( i in 1:length(list1) )
        cat( "i is ", list1[[i]], "\n" )
    return (0)
}

I ran it as:
    f1(2,4,10,12)
and I get:
    i is  2
    [1] 0
I was hoping for
    i is  2
    i is  4
    i is  10
    i is  12

I am hoping somebody can tell me what I am doing wrong. Is using a list a bad idea?

Thanks
Bob

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to