Created
May 6, 2024 06:14
-
-
Save strengejacke/bd14a299a806d5e2d03347d5c274a7f9 to your computer and use it in GitHub Desktop.
Compile R Report (HTML/PDF/Word file from R scripts)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' --- | |
#' title: "Compile Report" | |
#' author: "" | |
#' date: "" | |
#' --- | |
#' Comments that are to be displayed as normal text are marked with `#'` | |
#' at the beginning of the line. Comments that are to be displayed as | |
#' code are marked with `#` at the beginning of the line. | |
# This is a comment for R code | |
x <- 1 | |
#' # Headings | |
#' | |
#' Headings are introduced with `#` after the comment. 1x `#` for | |
#' heading 1, 2x `#` for heading 2, etc., e.g: `#' ## heading 2`. | |
#' | |
#' # Run R-code | |
#' | |
#' R-Code is run automatically | |
library(datawizard) | |
data(mtcars) | |
data_tabulate(mtcars, "cyl") | |
#' If only the output is to be displayed without the code, then there | |
#' must be a comment with `+ echo=FALSE` before the code block, | |
#' e.g. `#+ echo=FALSE`. | |
#+ echo=FALSE | |
library(datawizard) | |
data(mtcars) | |
data_tabulate(mtcars, "cyl") | |
#' # HTML-tables instead text output | |
#' | |
#' HTML can also be used, hence you can create nice tables with `print_html()` | |
library(datawizard) | |
data(mtcars) | |
data_tabulate(mtcars, "cyl") |> print_html() | |
#' # Text formatting | |
#' | |
#' Text can be formatted using markdown syntax, e.g. `**word**` for | |
#' **bold** or `*word*` für *italic*. | |
#' | |
#' It is important that the text, including blank lines, is continued as comment, e.g. | |
#' | |
#' | |
#' ``` | |
#' #' First row | |
#' #' | |
#' #' Second row | |
#' ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
RStudio:
Here's the icon in to compile reports in RStudio:
VSCode
This is a possible keybinding for VS Code: