[R] most stable way to output text layout

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Sat Jun 12 18:53:44 CEST 2021


Can't say this appeals to me, but sprintf would make a difference:

    apply(
      mat,1,
      function(x) {
        x[is.na(x)] <-""
        cat(paste(sprintf("%16s",x)),"\n")
      })

On June 12, 2021 9:24:51 AM PDT, Jeremie Juste <jeremiejuste using gmail.com> wrote:
>Hello,
>
>I'm trying to print a razor thin front-end using just text matrices and
>the command prompt.
>
>I admit that it is a bit crazy, it seems to do the job and is very
>quick
>to implement...  Except that I don't know of to fix the layout.
>
>I'm just seeking to map column names to a standard domain in an
>interactive way.
>
>For instance, at one iteration, the following matrix is produced:
>
>mat <- structure(c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
>NA, NA, NA, NA, NA, NA, NA, "a", "b", "c", "d", "e", "f", "g", 
>"h", "i", "j", NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
>NA, NA, NA, NA, NA, NA, NA, NA, "n_missing:", "n_unique:", "freq:", 
>NA, NA, NA, NA, NA, NA, NA, "0", "10", NA, "a", "1", NA, NA, 
>NA, NA, NA, NA, NA, NA, "b", "1", NA, NA, "best match: [1]:", 
>NA, NA, NA, NA, NA, "c", "1", NA, NA, "foo", NA, NA, NA, NA, 
>NA, "d", "1", NA, NA, NA, NA, NA), .Dim = c(10L, 10L))
>
>
>which I represent in the console using the following command
>
>
>    apply(
>      mat,1,
>      function(x) {
>        x[is.na(x)] <-""
>        cat(x,"\n")
>      })
>
>Do you have any suggestion for how can I have better control on the
>print layout of the  matrix so that I can fix the width of each cell?
>
>Best regards,

-- 
Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list