render_code {TBox}R Documentation

Generate a file with formatted code

Description

Format a piece of code to copy it into an email, a pdf, a document, etc.

Usage

render_code(
  output = "word",
  browser = getOption("browser"),
  font_size = 12,
  code = TRUE,
  ...
)

Arguments

output

a string. The output format ("pdf", "html" or "word" are accepted)

browser

a string. The path to the browser which will open the generated file format

font_size

a numeric. The font size in pdf format.

code

a boolean. Does the copied content is

...

other arguments passed to R chunk (for example eval = TRUE, echo = FALSE...)

Details

This function allows the user to generate formatted code (for email, document, copy, message, etc.) on the fly.

It accepts mainly word, pdf and html formats, but any format accepted by rmarkdown on the computer.

To use this function, simply copy a piece of code and run render_code() with the arguments that interest us. If you want content that is not R code, use the code argument to FALSE. In pdf format, you can change the font size using the font_size argument. Also, you can change the browser that opens the file by default with the browser argument. With the argument ..., you can specify knitr arguments to be included in the chunk. For example, you can add eval = TRUE (if you want the R code to be evaluated (and the result displayed)), echo = FALSE (if you don't want to display the code)... More information in the function opts_chunk or directly https://yihui.org/knitr/options/#chunk-options to see all available options and their descriptions.

Value

This function returns invisibly (with invisible()) NULL.

Examples

# Copy a snippet of code
if (clipr::clipr_available()) {
    clipr::write_clip("plot(AirPassengers)", allow_non_interactive = TRUE)
}

render_code(
    output = "word",
    echo = TRUE
)

render_code(
    output = "html",
    eval = FALSE
)


render_code(
    output = "pdf",
    eval = TRUE,
    font_size = 16
)


[Package TBox version 0.1.2 Index]