'format.pval' has a major limitation in its implementation for example suppose a person had a vector like 'a' and the error being ±0.001.
> a <- c(0.1, 0.3, 0.4, 0.5, 0.3, 0.0001) > format.pval(a, eps=0.001) The person wants to have the 'format.pval' output with 2 digits always showing like this [1] "0.10" "0.30" "0.40" "0.50" "0.30" "<0.001" How ever format.pval can only display this [1] "0.1" "0.3" "0.4" "0.5" "0.3" "<0.001" If this was the 'format' function this could be corrected by setting the 'nsmall' argument to 2. But 'format.pval' has no ability to pass arguments to format. I think that the best solution would be to give 'format.pval' a '...' argument that would get passed to all the 'format' function calls in 'format.pval'. I have attached a patch that does this. This patch is against svn r-release-branch, but it also works with r-devel. Charles Dupont -- Charles Dupont Computer System Analyst School of Medicine Department of Biostatistics Vanderbilt University
Index: src/library/base/R/format.R =================================================================== --- src/library/base/R/format.R (revision 40768) +++ src/library/base/R/format.R (working copy) @@ -43,7 +43,7 @@ } format.pval <- function(pv, digits = max(1, getOption("digits")-2), - eps = .Machine$double.eps, na.form = "NA") + eps = .Machine$double.eps, na.form = "NA", ...) { ## Format P values; auxiliary for print.summary.[g]lm(.) @@ -55,8 +55,8 @@ ## be smart -- differ for fixp. and expon. display: expo <- floor(log10(ifelse(pv > 0, pv, 1e-50))) fixp <- expo >= -3 | (expo == -4 & digits>1) - if(any( fixp)) rr[ fixp] <- format(pv[ fixp], dig=digits) - if(any(!fixp)) rr[!fixp] <- format(pv[!fixp], dig=digits) + if(any( fixp)) rr[ fixp] <- format(pv[ fixp], dig=digits, ...) + if(any(!fixp)) rr[!fixp] <- format(pv[!fixp], dig=digits, ...) r[!is0]<- rr } if(any(is0)) { @@ -67,7 +67,7 @@ digits <- max(1, nc - 7) sep <- if(digits==1 && nc <= 6) "" else " " } else sep <- if(digits==1) "" else " " - r[is0] <- paste("<", format(eps, digits=digits), sep = sep) + r[is0] <- paste("<", format(eps, digits=digits, ...), sep = sep) } if(has.na) { ## rarely rok <- r Index: src/library/base/man/format.pval.Rd =================================================================== --- src/library/base/man/format.pval.Rd (revision 40768) +++ src/library/base/man/format.pval.Rd (working copy) @@ -6,13 +6,14 @@ \alias{format.pval} \usage{ format.pval(pv, digits = max(1, getOption("digits") - 2), - eps = .Machine$double.eps, na.form = "NA") + eps = .Machine$double.eps, na.form = "NA", \dots) } \arguments{ \item{pv}{a numeric vector.} \item{digits}{how many significant digits are to be used.} \item{eps}{a numerical tolerance: see Details.} \item{na.form}{character representation of \code{NA}s.} + \item{\dots}{arguments passed to the \code{\link{format}} function.} } \value{ A character vector.
______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel