user2616437
user2616437

Reputation:

what is wrong with this list naming assignment?

Folks -

I'm going to keep my code here brief, as I think to those more familiar with R, it will be obvious. I am trying to use a function (not my own) that requires I feed it a list of named lists of parameters. I am having trouble naming the lists via a function I wrote to create each list element. Here is my function:

# for invoking grts
stratumdesign<- function(ns, points, oversamp) {
    stratumname<-as.character(ns)
    print("from function")
    print(stratumname)

    designlist<-list(ns=c(panel=points, seltype="Equal", over=oversamp))
    return(designlist)
}

.. I have tried both having the function call have ns be the integer it is in the originating code, or be passed as a character. Neither work. What I'm illustrating here to myself w/in the function is that ns gets properly passed to the function, but the resulting list returned is always named "$ns" when I want it to be the value passed AS ns! What on Earth am I doing wrong, here?

Upvotes: 0

Views: 60

Answers (1)

joran
joran

Reputation: 173517

Since this deserves an actual answer, not just a comment...

Try something more like this:

stratumdesign<- function(ns, points, oversamp) {
    print("from function")
    print(stratumname)

    designlist<-list(c(panel=points, seltype="Equal", over=oversamp))
    names(designlist) <- as.character(ns)
    return(designlist)
}

Upvotes: 1

Related Questions