Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to align both header and data? #380

Open
agguser opened this issue Oct 24, 2020 · 9 comments
Open

How to align both header and data? #380

agguser opened this issue Oct 24, 2020 · 9 comments

Comments

@agguser
Copy link

agguser commented Oct 24, 2020

For example:

$ M() { echo "s,i,f\na,1,1.1\nbb,22,22.22" | mlr --c2p "$@"; }

$ M cat
s  i  f
a  1  1.1
bb 22 22.22

$ M format-values -i '%2lld' -f '%5.2lf'
s  i  f
a   1  1.10
bb 22 22.22

$ M put '$i=fmtnum($i,"%2lld"); $f=fmtnum($f,"%5.2lf")'
s  i  f
a   1  1.10
bb 22 22.22

But what I want is that both header and data has same alignment:

s   i     f
a   1  1.10
bb 22 22.22

It would be great if there is ralign verb to right-align specific fields, e.g. mlr --c2p ralign -f i,f.

@johnkerl
Copy link
Owner

looking ...

@johnkerl
Copy link
Owner

I think you just want mlr --opprint --right ... ?

$ mlr --c2p cat sif.csv
s  i  f
a  1  1.1
bb 22 22.22

$ mlr --c2p --right cat sif.csv
 s  i     f
 a  1   1.1
bb 22 22.22

@agguser
Copy link
Author

agguser commented Oct 26, 2020

I want to right-align only "number" columns (i, f), not "text" columns (s).

@johnkerl
Copy link
Owner

D'oh.

@johnkerl
Copy link
Owner

Yes I had imagined this some while back but wasn't sure if there were sufficient demand. Now that there are two of us who have thought of this ... probably rises to the level of being worth coding up. ;)

@agguser
Copy link
Author

agguser commented Oct 26, 2020

Thanks. By the way, on second thought, instead of ralign verb, it should be --ralign {a,b,c} option for pprint.

@agguser
Copy link
Author

agguser commented Oct 28, 2020

Workaround:

$ echo "s,i,f\na,1,1.1\nbb,22,22.22" | mlr --c2t format-values -f '%.2lf' | column -t -s $'\t' -R 3
s   i       f
a   1    1.10
bb  22  22.22

@Poshi
Copy link
Contributor

Poshi commented Jul 28, 2021

One more interested!

I got here also looking on how to right-align only some of the columns in a pprint output.
I'm generating a small report tool that will list a set of data consisting on text, numbers (integers and floats) and times (in the format [[dd-]hh:]mm:ss). Humans need numbers to be right aligned to be easy to skim over them (comma aligned, to be more precise, which is equivalent to right aligned in case of integers and floats formatted with a fixed number of decimals). On the other hand, text needs to be left aligned for human comfort. In the middle is the time data: it is handled as a string, but it should be right aligned as well so the hours, minutes and seconds are always aligned.

Some kind of "alignment specification" would be good. The "ralign" proposal seems good, but I want to add something:

  • Given that left alignment is the default, per column right alignment is missing... and it would be good to have "center" ability in the same go. In fact, I would go for a parameter to specify default alignment (left, right, center) and a verb to specify column alignments.
  • Giving the columns as an option to pprint instead of a verb could make it difficult to apply this option to newly created fields on the fly through a put command.

@nikbucher
Copy link

nikbucher commented Jun 9, 2023

+1
that --ralign {a,b,c} option would be great or some kind of alignment "spec"

@johnkerl johnkerl removed the wishlist label Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants