Enjoy.) I recommend knitr and kable for people just getting into writing dynamic documents (also called literate statistical programming) because they’re the easiest and most flexible tools, especially since they can be used to create Word documents (not just pdfs or html pages). (Side note to the fiber enthusiasts: Yes, you’re not imagining it - pretty much all of this stuff is playfully named after yarn, knitting, and textile references. We’ll use one of the most basic functions for creating tables, kable, which is from one of the most user-friendly packages for combining R code and output together, knitr. In this tutorial, I’ll cover examples for one common model (an analysis of variance, or ANOVA) and show you how you can get table and in-line output automatically. I’m writing this post in R Studio as an R-markdown document.Įven if you’ve never used markdown or R-markdown before, you can jump right in and start getting properly formatted output from R. I wrote my entire dissertation in R Studio, in fact, using sweave to integrate my R code with LaTeX typesetting. I almost never type out my results anymore I let R do it for me. These are called dynamic documents, and they’re awesome. Happily, R integrates beautifully with output documents, allowing you to ask the computer to fill in the numbers in your tables and text for you, so you never have to wake up in a cold sweat panicking about a typo in your correlation matrix. Through the years, I’ve learned that the only sure way to reduce human error is to give humans (including myself) as little opportunity to interfere in the process as possible. No matter how carefully I check my work, there’s always the nagging suspicion that I could have confused the contrasts for two different factors, or missed a decimal point or a negative sign.Īlthough I’m usually overreacting, I think my paranoia isn’t completely misplaced - little errors are much too easy to make, and they can have horrifying consequences. And of course the YouTube algorithm had to remind me of more fun stuff.I don’t know what fears keep you up at night, but for me it’s worrying that I might have copy-pasted the wrong values over from my output. So naturally I had to incorporate it into my text somehow. My brain randomly reminded me of some dumb internet stuff from 6 years ago. Either before sending the data to gt() or with fmt() which we’ll cover in a sec. But if your desired format does not work, you can always format it manually. At least I’ve run into some troubles with that (see Issue). And if you’re familiar with HTML/CSS you can even apply custom styles that have not been implemented in. Just like in a ggplot we can style more or less every part of our table. Time to get to the most complicated part of our tables: Their theme. We’ve got the formatting options covered. # factor to apply to original width and height of svg from Wikipedia scale_size ') tibble( logo = r_logo_svg) |> gt() |> fmt_markdown( columns = 'logo') The latter is the correct German formatting. Here’s an example of that with day_m_year (not flexible) and yMMMd (flexible) using the German locale. Beware that month names may adapt to the locale but not the formatting. This means that they will adjust to locales. Notice that some of these styles are labeled as flexible. Usable in the fmt_date() and fmt_datetime() functions
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |