-
Notifications
You must be signed in to change notification settings - Fork 998
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
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,36 +18,24 @@ tables <- function(mb=TRUE, order.col="NAME", width=80, | |
data.table(NAME = dt_n, | ||
NROW = nrow(DT), | ||
NCOL = ncol(DT)) | ||
if (mb) | ||
# mb is an option because object.size() appears to be slow. | ||
# **TO DO: revisit** | ||
set(info_i, , "MB", | ||
#1048576 = 1024^2 | ||
round(as.numeric(object.size(DT))/1048576)) | ||
if (mb) set(info_i, , "MB", round(as.numeric(object.size(DT))/1024^2)) | ||
# mb is an option because object.size() appears to be slow. TO DO: revisit | ||
set(info_i, , "COLS", list(list(names(DT)))) | ||
set(info_i, , "KEY", list(list(key(DT)))) | ||
if (index) set(info_i, , "INDICES", list(list(indices(DT)))) | ||
info_i | ||
})) | ||
info[ , NROW := format(sprintf("%4s", prettyNum(NROW, big.mark=",")), justify="right")] # %4s is for minimum width | ||
info[ , NCOL := format(sprintf("%4s", prettyNum(NCOL, big.mark=",")), justify="right")] | ||
if (mb) { | ||
total = sum(info$MB) | ||
info[ , MB := format(sprintf("%2s", prettyNum(MB, big.mark=",")), justify="right")] | ||
} | ||
if (!order.col %in% names(info)) stop("order.col='",order.col,"' not a column name of info") | ||
info = info[base::order(info[[order.col]])] # base::order to maintain locale ordering of table names | ||
m = as.matrix(info) | ||
colnames(m)[2] = sprintf(paste("%",nchar(m[1,"NROW"]), "s", sep=""), "NROW") | ||
colnames(m)[3] = sprintf(paste("%",nchar(m[1,"NCOL"]), "s", sep=""), "NCOL") | ||
if (mb) colnames(m)[4] = sprintf(paste("%", nchar(m[1,"MB"]), "s", sep=""), "MB") | ||
m[ , "COLS"] = substring(m[,"COLS"], 1L, width) | ||
m[ , "KEY"] = substring(m[,"KEY"], 1L, width) | ||
if (!silent) { | ||
print(m, quote=FALSE, right=FALSE) | ||
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 | ||
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="") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good spot! |
||
} | ||
invisible(info) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 offormat.default
can be used instead of callingsprintf
:little test I ran to convince myself:
There was a problem hiding this comment.
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 oftables
? Or something inutils.R
? (justgrep
ed forsprintf
, only used in this capacity here withintables
)