r - Check which arguments are missing/NULL -


i have 2 questions both arose lack of understanding how arguments in r function handled.

  1. 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)) } 
  2. 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 true first argument:

    > g(y=1)     x     y  false false  

  1. this seems reasonable thing do. of course, if had many more arguments think sapply

  2. 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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -