Re: [R] most stable way to output text layout

2021-06-13 Thread Jeremie Juste
Hello Jim, On Sunday, 13 Jun 2021 at 08:40, Jim Lemon wrote: > Hi Jeremie, > Or assuming that the matrix will always contain strings: > > tabify<-function(x,col_names=NULL) { > # convert NAs to "NA" > x[is.na(x)]<-"NA" > # if this matrix doesn't have any column names > if(is.null(col_names))

Re: [R] most stable way to output text layout

2021-06-12 Thread Jim Lemon
Hi Jeremie, Or assuming that the matrix will always contain strings: tabify<-function(x,col_names=NULL) { # convert NAs to "NA" x[is.na(x)]<-"NA" # if this matrix doesn't have any column names if(is.null(col_names)) col_names<-LETTERS[1:ncol(x)] # get the format argument for sprintf tab_widt

Re: [R] most stable way to output text layout

2021-06-12 Thread Jeremie Juste
Hello, Many thanks to you all for the prompt reply. Thanks for sharing. On Saturday, 12 Jun 2021 at 09:53, Jeff Newmiller wrote: > Can't say this appeals to me, but sprintf would make a difference: > > apply( > mat,1, > function(x) { > x[is.na(x)] <-"" > cat(paste(

Re: [R] most stable way to output text layout

2021-06-12 Thread Avi Gross via R-help
[67] [73] b 1 best match: [1]: [79] c [85] 1 foo [91] d 1 [97] I made it left justified and

Re: [R] most stable way to output text layout

2021-06-12 Thread Greg Minshall
Jeremie, i'm not totally sure i understand your desire. but, does this help? mx <- max(nchar(mat), na.rm=TRUE) apply( mat,1, function(x) { x[is.na(x)] <-"" cat(sprintf("%*s", mx, x), "\n") }) cheers, Greg __ R-he

Re: [R] most stable way to output text layout

2021-06-12 Thread Jeff Newmiller
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 wrote: >Hello, > >I'm trying to print a razor thin front-end

[R] most stable way to output text layout

2021-06-12 Thread Jeremie Juste
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