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

Feature request: fmt_bytes() #310

Closed
wlandau opened this issue Jun 20, 2019 · 2 comments · Fixed by #750
Closed

Feature request: fmt_bytes() #310

wlandau opened this issue Jun 20, 2019 · 2 comments · Fixed by #750

Comments

@wlandau
Copy link

wlandau commented Jun 20, 2019

For performance studies like this one, it would be super helpful to pretty print sizes in bytes, with automatic conversion to KB, MB, GB, etc. as needed. Is this within scope?

@rich-iannone
Copy link
Member

This is definitely within scope (and internally talked about before). Thanks for posting this as an issue, we hope to get to it soon!

@rich-iannone
Copy link
Member

Use the following, taken from pryr:::print.bytes():

function (x, digits = 3, ...) 
{
    power <- min(floor(log(abs(x), 1000)), 4)
    if (power < 1) {
        unit <- "B"
    }
    else {
        unit <- c("kB", "MB", "GB", "TB")[[power]]
        x <- x/(1000^power)
    }
    formatted <- format(signif(x, digits = digits), big.mark = ",", 
        scientific = FALSE)
    cat(formatted, " ", unit, "\n", sep = "")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants