Skip to content
Prev 67664 / 398506 Next

Printing integers in R "as is"

On Thu, Apr 14, 2005 at 02:32:33PM +0300, Firas Swidan wrote:

            
For printing formatted output of this kind, you're generally much better
off using sprintf, as in

    cat(sprintf("%2s  %8d  %8d  %s\n", orientation, as.integer(start), as.integer(end), names));

or, if length(names) > 1, you might consider

    sprintf("%2s  %8d  %8d  %s\n", orientation, as.integer(start), as.integer(end), paste(names, collapse = ", "));

etc. This assumes that start and end are numeric vectors of length 1,
which seems sensible to me based on the context I can conclude from the
variable names, and I think that sprintf in R-devel, and R 2.1.0 in the
near future will cycle over longer vectors too.
Are you certain that start and end are integer vectors? If in doubt,
check typeof(start) -- the fact that the values are integer does not
necessarily mean that the type is integer.

Best regards, Jan