[R] Determining whether a function's return value is assigned

Paul Laub tyrosine at gmail.com
Sat Jun 30 12:44:06 CEST 2007


Dear all,

Does R offer a means by which a function can determine
whether its return value is assigned? I am using R
2.4.1 for Windows.

Suppose what I am looking for is called
"return.value.assigned". Then one might use it like
this

    myfunction <- function () {
        # Create bigobject here

        if (return.value.assigned()) {
            bigobject
        } else {
            summary(bigobject)
        }
    }

and

    x <- myfunction()  # bigobject is assigned

    myfunction()       # summary of bigobject is printed

Octave and MATLAB have the nargout function that does
what I want, and Perl has the wantarray function
detecting the context in which a function is called.
Perhaps match.call() can be made to do what I want,
but, if so, I don't see it in reading the
documentation.

Sincerely,

Paul Laub



More information about the R-help mailing list