pacman::p_load(digit) rinline <- function(code) { sprintf('<code class="r">``` `r %s` ```</code>', code) } desc <- suppressWarnings(readLines("DESCRIPTION")) regex <- "(^Version:\\s+)(\\d+\\.\\d+\\.\\d+)" loc <- grep(regex, desc) ver <- gsub(regex, "\\2", desc[loc]) verbadge <- sprintf('<a href="https://img.shields.io/badge/Version-%s-orange.svg"><img src="https://img.shields.io/badge/Version-%s-orange.svg" alt="Version"/></a></p>', ver, ver) ```` [![Build Status](https://travis-ci.org/trinker/digit.svg?branch=master)](https://travis-ci.org/trinker/digit) [![Coverage Status](https://coveralls.io/repos/trinker/digit/badge.svg?branch=master)](https://coveralls.io/r/trinker/digit?branch=master) `r verbadge` **digit** contains tools to assist in the formatting of numbers for publication. Tools include the removal of leading zeros, standardization of number of digits, and a p-value formatter. # Installation To download the development version of **digit**: Download the [zip ball](https://github.com/trinker/digit/zipball/master) or [tar ball](https://github.com/trinker/digit/tarball/master), decompress and run `R CMD INSTALL` on it, or use the **pacman** package to install the development version: ```r if (!require("pacman")) install.packages("pacman") pacman::p_load_gh("trinker/digit")
You are welcome to: submit suggestions and bug-reports at: https://github.com/trinker/digit/issues send a pull request on: https://github.com/trinker/digit/ * compose a friendly e-mail to: tyler.rinker@gmail.com
f(c(0.0, 0, .2, -00.02, 1.122222, pi, "A"))
We can see its use in actual model reporting as well:
mod1 <- t.test(1:10, y = c(7:20)) sprintf( "t = %s (%s)", f(mod1$statistic), p(mod1$p.value) )
mod2 <- t.test(1:10, y = c(7:20, 200)) sprintf( "t = %s (%s)", f(mod2$statistic, 2), p(mod2$p.value, digits = 2) )
We can build a function to report model statistics:
report <- function(mod, stat = NULL, digits = c(0, 2, 2)) { stat <- if (is.null(stat)) stat <- names(mod[["statistic"]]) sprintf( "%s(%s) = %s, %s", stat, paste(f(mod[["parameter"]], digits[1]), collapse = ", "), f(mod[["statistic"]], digits[2]), p(mod[["p.value"]], digits = digits[3]) ) } report(mod1) report(oneway.test(count ~ spray, InsectSprays)) report(chisq.test(matrix(c(12, 5, 7, 7), ncol = 2)))
This enables in-text usage as well. First set up the models in a code chunk:
mymod <- oneway.test(count ~ spray, InsectSprays)
And then use r rinline("report(mymod)")
resulting in a report that looks like this: r report(mymod)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.