[R] Return invisible list

S Ellison S.Ellison at LGCGroup.com
Fri Jul 8 15:46:59 CEST 2011


> -----Original Message-----
> [mailto:r-help-bounces at r-project.org] On Behalf Of francisco.ahued
> Subject: [R] Return invisible list
> 
> x=read.table("data.txt",header=T)
> goa=(x[,3])
> meplot(goa)
> 
> I can see the plot, but I would like to see the values of the 
> x and y axis. 
> 

Something returned as invisible is returned but not printed. 
You just need to catch it in a suitable variable. That's what you do with any other function where you want to keep the value: 

 x=read.table("data.txt",header=T)
 goa=(x[,3])
mplist <-  meplot(goa) #assigns the output to a variable called mplist

mplist  #calls the default print method for that object.

If you don't need to keep the values for re-use, putting something in parentheses evaluates the expression and returns the result, effectively removing the invisibility cloak without explicit assignment.

Example

z<-rnorm(100)
hist( z ) #returns invisible list

but

( hist( z ) ) #additionally displays the output.

S Ellison*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}



More information about the R-help mailing list