R functions, access to parameter names -


i have following code:

fn <- 'george' mn <- 'walker' ln <- 'bush' f <- function(...) { print(list(...)) } 

when call it, produces following output:

f(fn,mn,ln)   [[1]]   [1] "george"    [[2]]   [1] "walker"    [[3]]   [1] "bush" 

suppose wanted similar (note parameter names):

fn:george mn:walker ln:bush 

question: know how values of arguments inside function. how names of arguments inside function?

thanks, cc.

you may use

f <- function(...) {      nm1 <- as.list(match.call()[-1])      val <- list(...)    cat(paste(nm1, val, sep=":", collapse="\n"),'\n') } f(fn,mn,ln) #fn:george #mn:walker #ln:bush  

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -