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

Fixed quotes showing in tables() output in dev. #2565

Merged
merged 4 commits into from
Jan 15, 2018
Merged

Conversation

mattdowle
Copy link
Member

@mattdowle mattdowle commented Jan 13, 2018

In master before this PR I was seeing quotes and a NULL in the output of tables() as follows.

> DT=data.table(1L)
> tables()
     NAME NROW   NCOL   MB   COLS KEY   
[1,] "DT" "   1" "   1" " 0" "V1" "NULL"
Total: 0MB

Seems to have arose in PR #1804 for issue #1648.
This PR simplifies tables() by leaving more of the formatting to standard print(DT) rather than creating a character matrix (something I did originally and was always a bit messy.)
Please check @MichaelChirico -- thanks.

@MichaelChirico
Copy link
Member

MichaelChirico commented Jan 13, 2018 via email

@codecov-io
Copy link

codecov-io commented Jan 13, 2018

Codecov Report

Merging #2565 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2565      +/-   ##
==========================================
- Coverage   91.39%   91.39%   -0.01%     
==========================================
  Files          63       63              
  Lines       12101    12097       -4     
==========================================
- Hits        11060    11056       -4     
  Misses       1041     1041
Impacted Files Coverage Δ
R/print.data.table.R 98.13% <100%> (+0.03%) ⬆️
R/tables.R 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 86e3786...d94ad32. Read the comment docs.

R/tables.R Outdated
if (mb) cat("Total: ", prettyNum(as.character(total), big.mark=","), "MB\n", sep="")
# prettier printing on console
tt = copy(info)
tt[ , NROW := format(sprintf("%4s", prettyNum(NROW, big.mark=",")), justify="right")] # %4s is for minimum width
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the width argument of format.default can be used instead of calling sprintf:

format(prettyNum(NROW, big.mark=","), width = 4L, justify="right")

little test I ran to convince myself:

all(replicate(1000, {
  ns = prettyNum(sample(20000, 10), big.mark = ',')
  wid = format(sprintf('%4s', ns), justify = 'right')
  spr = format(ns, width = 4L, justify = 'right')
  identical(wid, spr)
}))
# [1] TRUE

Copy link
Member

@MichaelChirico MichaelChirico Jan 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway we use the format(prettyNum(...)) enough times here to warrant a function (commaNum? print_num?). Maybe defined within the scope of tables? Or something in utils.R? (just greped for sprintf, only used in this capacity here within tables)

R/tables.R Outdated
tt[ , NCOL := format(sprintf("%4s", prettyNum(NCOL, big.mark=",")), justify="right")]
if (mb) tt[ , MB := format(sprintf("%2s", prettyNum(MB, big.mark=",")), justify="right")]
print(tt, class=FALSE, nrow=Inf)
if (mb) cat("Total: ", prettyNum(as.character(sum(info$MB)), big.mark=","), "MB\n", sep="")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why as.character here? prettyNum should handle the type conversion?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot!

Copy link
Member

@MichaelChirico MichaelChirico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's good to go. agree with move to use print.data.table facilities -- what's #1523 otherwise?

@mattdowle
Copy link
Member Author

Thanks @MichaelChirico. Good spots and changes.

@mattdowle mattdowle merged commit 0c060fe into master Jan 15, 2018
@mattdowle mattdowle deleted the tables_fix branch January 15, 2018 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants