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
Post a Comment