[R] Printing
Bert Gunter
bgunter@4567 @end|ng |rom gm@||@com
Sun Aug 11 16:57:54 CEST 2024
Just for reference, R's "preferred" way to handle printing is to
create "classed" objects from a function that produces all the
necessary information and have an appropriate "print" method, i.e.
function, for that class to print it. R has several class object
systems that can do this, including the basic S3 system. Spend some
time with an R tutorial or two to learn more, as it's clear from your
query that your R knowledge would benefit from such effort (though I
suppose all of us could say the same).
Cheers, Bert
On Sun, Aug 11, 2024 at 7:43 AM Steven Yen <styen using ntu.edu.tw> wrote:
>
> Thanks. Will try it.
>
> Have not tried it but I think the following may work:
>
> out$results<-NULL
>
> out$results$ei<-ap
>
> out$results$vi<-vap
>
> All I need is printing by returning out (unless I turn it off). And,
> retrieve ap and vap as needed as shown above. Guess I need to read more
> about invisible.
>
> On 8/11/2024 10:09 PM, Rui Barradas wrote:
> > Às 09:51 de 11/08/2024, Steven Yen escreveu:
> >> Hi
> >>
> >> In the following codes, I had to choose between printing (= TRUE) or
> >> deliver something for grab (ei, vi). Is there a way to get both--that
> >> is, to print and also have ei and vi for grab? Thanks.
> >>
> >> Steven
> >>
> >> ...
> >>
> >> out<-round(as.data.frame(cbind(ap,se,t,p)),digits)
> >> out<-cbind(out,sig)
> >> out<-out[!grepl(colnames(zx)[1],rownames(out)),]
> >> if(printing){
> >> cat("\nAPPs of bivariate ordered probit probabilities",
> >> "\nWritten by Steven T. Yen (Last update: 08.11.24)",
> >> "\ny1.level=", y1.level,
> >> " y2.level=", y2.level,
> >> "\njoint12 =", joint12,
> >> "\nmarg1 =", marg1,
> >> "\nmarg2 =", marg2,
> >> "\ncond12 =", cond12,
> >> "\ncond21 =", cond21,
> >> "\nCovariance matrix:",vb.method,
> >> "\nWeighted =", weighted,
> >> "\nAt means =", mean,
> >> "\nProb x 100 =", times100,
> >> "\ntesting =" , testing,
> >> "\nuse_bb_and_vbb = ",use_bb_and_vbb,
> >> "\nsample size =", length(y1),"\n")
> >> if (!resampling) cat("\nSEs by delta method","\n")
> >> if (resampling) cat("\nSEs K-R resampling with",ndraws,"draws\n")
> >> return(out)
> >> } else {
> >> invisible(list("ei"=ap,"vi"=vap))
> >>
> >> ______________________________________________
> >> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> 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.
> >
> > Hello,
> >
> > Maybe change the end of the code to return a bigger list.
> >
> >
> > ll <- list(out = out, ei = ap, vi = vap)
> > return(ll)
> > } else {
> > invisible(list("ei"=ap,"vi"=vap))
> >
> >
> > Hope this helps,
> >
> > Rui Barradas
> >
> >
> >
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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