![]() The package vignette illustrates package usage in detail. With a tighter focus on what formatdown is to accomplish compared to docxtools, I have reduced the dependencies to checkmate, wrapr, and data.table. ![]() For example, the markup for x = 1.23E-4 in decimal notation is given by, $x =$ `r format_power(x = 1.234E-4, omit_power = c(-4, 0))`Ī final (internal) improvement is a more balanced approach to package dependencies. The third improvement is the addition of an option for omitting powers-of-ten notation over a range of exponents. For example, the markup for Avogadro’s number in scientific notation is given by, $N_A =$ `r format_power(x, digits = 5, format = "sci")` The second improvement is the addition of an option for scientific notation. Which is rendered (in this output document) as. To illustrate formatting a scalar value inline, the markup for Avogadro’s number ( x = 6.0221E+23) in engineering format is given by, $N_A =$ `r format_power(x, digits = 5, format = "engr")` The benefits of this change are: 1) simpler code that should be easier to revise and maintain 2) scalar values can be formatted for rendering inline and 3) data frames can still be formatted, by column, using lapply(). The primary design change is that the format_power() function operates on a numerical vector instead of a data frame. With formatdown, my goal is to provide similar functionality but with more concise code, greater flexibility, and a more balanced approach to package dependencies. I also failed to take advantage of formatC() in constructing the output. This could have been simplified with judicious use of lapply(), with which I was not sufficiently experienced at the time. I wrote its formatting function to accept a data frame as input, which entailed a lot of programming overhead to separate numerical from non-numerical variable classes and to reassemble them after the numerical columns were formatted. That implementation has several shortcomings. My first attempt to provide powers-of-ten formatting was in my 2016 package, docxtools. Table 1: Rendering a number using different formats Notation In the examples, I use data.table syntax for data manipulation, though the code can be translated into base R or dplyr syntax if desired. The R code for the post is listed under the “R code” pointers. To illustrate the different formats, I show in Table 1 the same number rendered using different formats, all with 4 significant digits. Provides two powers-of-ten formatting options-scientific notation and engineering notation-with an option to omit powers-of-ten notation for a specified range of exponents. This first version has one function only, format_power(), for converting numbers to character strings formatted in powers-of-ten notation and delimited in $.$ for rendering as inline equations in. Initial release of the formatdown R package providing tools for formatting output in rmarkdown or quarto markdown documents. Convert the elements of a numerical vector or data frame column to character strings in which the numbers are formatted using powers-of-ten notation in scientific or engineering form and delimited for rendering as inline equations in an rmarkdown document.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |