Re: [R] Using str() in a function.

2011-07-15 Thread Duncan Murdoch
On 15/07/2011 1:44 PM, Bert Gunter wrote: Below. -- Bert On Fri, Jul 15, 2011 at 10:31 AM, andrewH wrote: > Thanks, everybody, this has been very edifying. One last question: > > It seems that sometimes when a function returns something and you don't > assign it, it prints to the console, an

Re: [R] Using str() in a function.

2011-07-15 Thread Bert Gunter
Below. -- Bert On Fri, Jul 15, 2011 at 10:31 AM, andrewH wrote: > Thanks, everybody, this has been very edifying. One last question: > > It seems that sometimes when a function returns something and you don't > assign it, it prints to the console, and sometimes it doesn't. I'm not sure > I unders

Re: [R] Using str() in a function.

2011-07-15 Thread David Winsemius
On Jul 15, 2011, at 1:31 PM, andrewH wrote: Thanks, everybody, this has been very edifying. One last question: It seems that sometimes when a function returns something and you don't assign it, it prints to the console, and sometimes it doesn't. I'm not sure I understand which is which. My

Re: [R] Using str() in a function.

2011-07-15 Thread andrewH
Thanks, everybody, this has been very edifying. One last question: It seems that sometimes when a function returns something and you don't assign it, it prints to the console, and sometimes it doesn't. I'm not sure I understand which is which. My best current theory is that, if the function return

Re: [R] Using str() in a function.

2011-07-13 Thread Bert Gunter
Folks: To thrash the dead horse a little more ... > So, what about this one: > GG<-c(1:4) > testX3 <- function(X) {summary(X); return(str(X))} > testX3(GG) > > int [1:4] 1 2 3 4 > > I thought this was ignoring the summary() because it evaluates the return() > first.  If it does the return(str(X))

Re: [R] Using str() in a function.

2011-07-13 Thread Daniel Malter
As long as you just want to display it, use print() GG<- c(1,2,3) print(summary(GG),str(GG)) Output: num [1:3] 1 2 3 Min. 1st Qu. MedianMean 3rd Qu.Max. 1.0 1.5 2.0 2.0 2.5 3.0 HTH, Daniel andrewH wrote: > > Using str() in a function. > > I am in th

Re: [R] Using str() in a function.

2011-07-13 Thread andrewH
Dear Peter-- You write: >>Andrew is being seriously confused. The return(ans) is of course executed when you get to it, returning the value of `ans` and terminating the function. Anything after that is _ignored_. There is no such thing as a "previous return()" affecting what str() does -- that woul

Re: [R] Using str() in a function.

2011-07-13 Thread David Winsemius
On Jul 13, 2011, at 10:54 PM, andrewH wrote: David -- Ah! Excellent. OK, that explains Dennis's function's output. Print(str(X)) evaluates str(X), sending the usual str() output to the console as a side effect, and then prints what str() returns, which is NULL. And invisible() prints NULL a

Re: [R] Using str() in a function.

2011-07-13 Thread andrewH
David -- Ah! Excellent. OK, that explains Dennis's function's output. Print(str(X)) evaluates str(X), sending the usual str() output to the console as a side effect, and then prints what str() returns, which is NULL. And invisible() prints NULL again, but we don't see NULL NULL, because the secon

Re: [R] Using str() in a function.

2011-07-13 Thread peter dalgaard
On Jul 14, 2011, at 01:48 , David Winsemius wrote: > > On Jul 13, 2011, at 7:31 PM, andrewH wrote: > >> Thanks, David & Dennis, that is very helpful. >> >> Let me state what I think I have learned, to see if I understand it >> correctly. Then I have two remaining questions. >> >> If a functio

Re: [R] Using str() in a function.

2011-07-13 Thread David Winsemius
On Jul 13, 2011, at 7:31 PM, andrewH wrote: Thanks, David & Dennis, that is very helpful. Let me state what I think I have learned, to see if I understand it correctly. Then I have two remaining questions. If a function contains more than one expression in its {}, it always returns the valu

Re: [R] Using str() in a function.

2011-07-13 Thread andrewH
Thanks, David & Dennis, that is very helpful. Let me state what I think I have learned, to see if I understand it correctly. Then I have two remaining questions. If a function contains more than one expression in its {}, it always returns the value of the last evaluated expression in its definiti

Re: [R] Using str() in a function.

2011-07-09 Thread Dennis Murphy
Hi: Is this what you're after? testX <- function(X) { print(summary(X)) print(str(X)) invisible() # returns nothing } testX(1:10) Min. 1st Qu. MedianMean 3rd Qu.Max. 1.003.255.505.507.75 10.00 int [1:10] 1 2 3 4 5 6 7 8 9 10 NULL See inline..

Re: [R] Using str() in a function.

2011-07-09 Thread David Winsemius
On Jul 9, 2011, at 4:20 AM, andrewH wrote: Using str() in a function. I am in the early phase of learning R, and I find I spend a lot of time trying to figure out what is actually in objects I have created or read in from a file. I'm trying to make a simple little function to display a c

[R] Using str() in a function.

2011-07-09 Thread andrewH
Using str() in a function. I am in the early phase of learning R, and I find I spend a lot of time trying to figure out what is actually in objects I have created or read in from a file. I'm trying to make a simple little function to display a couple of things about a object, let's say the summar