![]() There probably is already, but I figured I would write my own mini-guide on the things I do that make writing so much easier in RMarkdown. The above tweet seemed to be well received and someone asked if there was a tutorial. Ben Harrap ( ( BHarrap?)) February 9, 2022 ![]() Just knowing that if my cleaning or analysis changes it automatically flows down into the paper is magical #rstats I gotta say, it's so incredibly satisfying having written this paper using RMarkdown and automating every number in the text. If you’re a non-R user I hope this blog post convinces you to ditch other word processing software and make the jump to RMarkdown. RMarkdown, along with bookdown, has made my life so much easier when it comes to writing up papers and reports. Automatic numbering for tables and figures.Using a regular expression, the function returns all characters of the table_nums('tab_1') output located before the first colon. and table number), I have written the function f.ref. In order to return the desired output (prefix Tab. 1: German Bundesliga: Final Table 2015/16, Position 7-12” Otherwise, we wi'll get the following output: Since we have received a numbered table, it should also be possible to reference the table. 1: German Bundesliga: Final Table 2015/16, Position 7-12 Position It is important to separate inline code and code chunk. With fig.cap = tab.1_cap, we specify the caption of the first table. The next code snippet combines both inline code and a code chunk. table_nums <- captioner::captioner(prefix = "Tab.")Ĭaption = "German Bundesliga: Final Table 2015/16, Position 7-12")Ĭaption = "German Bundesliga: Final Table 2015/16, Position 12-18") Furthermore, we may also define a prefix ( Tab. We define both table name and table caption. In a first step, we define a function named table_nums and apply it to the tables' name and caption. Thanks to Alathea Letaw's captioner package, we can number tables and figures. knitr::kable(bundesligR::bundesligR,Ĭaption = "German Bundesliga: Final Table 2015/16, Position 1-6") As we can see, the caption will not be numbered and, thus, cannot be referenced in the document. With caption we can specify a simple table caption. In the first code snippet, we create a table using the kable function of the knitr package. Pacman::p_load(knitr, captioner, bundesligR, stringr) if (!require("pacman")) install.packages("pacman") It contains “all final tables of Germany's highest football league, the Bundesliga” Link. ![]() The dataset I will be using in this blog post is named bundesligR and part of the bundesligR package. The following code will install load and / or install the R packages required for this blog post. In this blog post, I will explain how to number and reference tables and figures in R Markdown files using the captioner package. However, since bookdown uses LaTex functionality, R Markdown files created with bookdown cannot be converted into MS Word (.docx) files. The recently published bookdown package makes it very easy to number and reference tables and figures ( Link). Unfortunately, R Markdown has no “native” method to number and reference table and figure captions. However, in scientific research papers or reports, tables and figures usually need to be numbered and referenced. R Markdown is a great tool to make research results reproducible.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |