[R] output of several "results" from a function

Ista Zahn istazahn at gmail.com
Tue Apr 3 13:37:17 CEST 2012


Hi Johannes,

You are on the right track. Just need to use the right line break
indicators, and explicitly call print. Like this:

tmp <- list(A="A123",B="B123")

summaryout=function(x,...){
       cat("This is output A:\n")
       print(x$A)
       cat("This is output B:\n")
       print(x$B)
}

summaryout(tmp)

Best,
Ista

On Tue, Apr 3, 2012 at 5:12 AM, Johannes Radinger <JRadinger at gmx.at> wrote:
> Hi,
>
> I try my first time to write a summary method for my function. The result of my function is a list of two objects (2 arrays). In my summary both objects should be displayed but with a some introductory text like:
>
> ls <- list(A="A123",B="B123")
>
> summaryout=function(x,...){
>        cat("This is output A:/n")
>        x$A
>        cat("This is output B:"/n")
>        x$B
> }
>
> How can I achieve that both list-elements are displayed and the lines inbetween, so that it looks nice?
>
> As the single list elements are arrays (partly 5-dimensional) is there a nice way to display them i a summary or print method?
>
> cheers,
>
>
> best regards,
>
> Johannes
> --
>
> Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a
>
> ______________________________________________
> R-help at r-project.org 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