[R] Function output
David Winsemius
dwinsemius at comcast.net
Sun Sep 20 18:27:43 CEST 2009
I think these examples will show what one can and cannot do with the
invisible function.
> f2 <- function(x,y) return(c(x, invisible(x^y)) )
> f2(2,2)
[1] 2 4 #so that not the right way to keep tree hidden
> f2 <- function(x,y) invisible(c(print(x),(x^y)) )
> f2(2,2)
[1] 2 # success x^y is calculate but not made visible on return
> print(f2(2,2))
[1] 2 # that came from within the f2 function
[1] 2 4 # that is what the value returned by f2
On Sep 20, 2009, at 11:21 AM, David Winsemius wrote:
>
> On Sep 20, 2009, at 10:59 AM, manta wrote:
>
>>
>> Good afternoon,
>> I know it is a simple question but I cannot figure out how to solve
>> this
>> issue.
>> I have a function that calculate two objects. I would like to choose
>> everytime about the tree object, with default to not show it.
>
> I cannot understand that. Perhaps you can try again to tell us what
> you want to do with tree?
>
>>
>> OP<-function(S=100,X,sigma,mu=0,r=0,time=1,n)
>> {
>> value=(S)
>> ......
>> tree = matrix(rev(tree), byrow = FALSE, ncol = n + 1)
>
> ... where did tree first get defined?
>
>> return(value[1])
>
> ... do you really want to return only value[1] _and_not_ tree? If
> you exit the function this way, tree will get lost.
>
>
>> }
>>
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list