r - Check which arguments are missing/NULL -
i have 2 questions both arose lack of understanding how arguments in r function handled.
- i vector indicating arguments of function - f(x,y)missing. there more elegant way following solution:- f <- function(x, y) { c(missing(x), missing(y)) }
- i implemented function returns logical variable indicating whether argument - null:- g <- function(x, y) { args_names <- as.list(environment()) sapply(args_names, is.null) }- while functions works intended, struggling understand why - g(y=1)not return- truefirst argument:- > g(y=1) x y false false
- this seems reasonable thing do. of course, if had many more arguments think - sapply
- for second question why not return args , see - r> g <- function(x, y) { + as.list(environment()) + } r> args = g(10) r> str(args$y) symbol- of course next question symbol, taken manual of knowledge 
symbols refer r objects. name of r object symbol. symbols can created through functions as.name , quote. symbols have mode "name", storage mode "symbol", , type "symbol". can coerced , character strings using as.character , as.name. naturally appear atoms of parsed expressions, try e.g. as.list(quote(x + y)).
Comments
Post a Comment