Missing argument argument R - R_MissingArg

There is information about the missing arguments in the inner elements of R: Missingness .
I am wondering if there is a way to set (rewrite) a function argument R_MissingArginside this function?
View:

f <- function(x){
    if(!missing(x)) message("x non missing")
    make_missing(x)
    if(missing(x)) message("x missing")
    invisible()
}

I understand that this is not recommended, and I should use x <- NULLand is.null(x)instead of checking for absence.

+4
source share
1 answer

You can replace the "x" with substitute():

var = substitute()
var
#Error: argument "var" is missing, with no default

And, although it’s safer to use x = substitute(), yours make_missingmight look something like this:

make_missing = function(x) assign(deparse(substitute(x)), 
                                  substitute(), 
                                  envir = parent.frame())

And your "f":

f = function(x)
{
    if(missing(x)) message("missing") else message("not missing")

    make_missing(x)
    if(missing(x)) message("missing") else message("not missing")
}
f()
#missing
#missing
f(7)
#not missing
#missing
+3
source

All Articles