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

Uwe Ligges ligges at statistik.uni-dortmund.de
Sat Jun 30 15:58:37 CEST 2007



Paul Laub wrote:
> 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.

Short answer: No.
Long answer: You want to have a class for the object called "bigobject" 
below and a print/show method that provides the summary for objects of 
that class.

Uwe Ligges





> 
> 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
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list