equation | R Documentation |
Extract or create a 'LaTeX' equation to describe a model, or directly from
'LaTeX' code. All objects supported by extract_eq()
are also supported by
the default method description. If labels (and units) are defined as
attributes to the data, they are automatically used in the equation in place
of the variable names.
equation(object, ...)
## Default S3 method:
equation(
object,
auto.labs = TRUE,
origdata = NULL,
labs = NULL,
swap_var_names = NULL,
...
)
## S3 method for class 'character'
equation(object, ...)
eq__(object, ...)
eq_(object, ...)
## S3 method for class 'inline_equation'
print(x, ...)
object |
An object with a model whose the equation is constructed. If a
character object is provided, it is concatenated into a single
character string and the equation class, otherwise it is not
transformed (it is supposed to be a valid 'LaTeX' equation). Remember that
backslashes must be doubled in regular R strings, or use the |
... |
Further parameters passed to |
auto.labs |
If |
origdata |
The original data set this model was fitted to. By default it
is |
labs |
Labels to change the names of elements in the |
swap_var_names |
Change the variable names for these values, regardless
of the values in |
x |
An inline_equation object generated by |
There are slight differences between equation()
, eq_()
and eq__()
:
equation()
returns a string with 'LaTeX' code and prints 'LaTeX' code at
the R console.
eq_()
returns the 'LaTeX' code surrounded by a dollar sign $...$
and is
suitable to build inline equations in R Markdown/Quarto documents by using
inline R code. It prints the rendered inline equation in the RStudio
Viewer or in the browser. So it is advised to rapidly preview the
resulting equation.
eq__()
returns the 'LaTeX' code not surrounded by dollar signs in a
single character string. It also prints the rendered inline equation in
the RStudio Viewer or in the browser.
It should be used in an R inline chunk inside a $$...$$
construct in a Markdown text. The result is a display equation that can
also be cross referenced in Quarto in the usual way if you label it, e.g.,
you use $$...$$ {#eq-label}
.
An object of class c("equation", "character")
.
iris_lm <- lm(data = iris, Petal.Length ~ Sepal.Length + Species)
summary(iris_lm)
equation(iris_lm)
# Providing directly the LaTeX code of the equation (variance of a sample)
equation("S^2_y = \\sum_{i=1}^{n-1} \\frac{(y_i - \\bar{Y})^2}{n}")
# Easier to write like this (avoiding the double backslashes):
eq1 <- equation(r"(S^2_y = \sum_{i=1}^{n-1} \frac{(y_i - \bar{Y})^2}{n})")
# Print raw text:
eq1
# Get a preview of the equation
if (interactive())
eq__(eq1)
# The same function can be used inside a `$$...$$ {#eq-label}` construct in
# R Markdown or Quarto to calcule a display equation that is also recognized
# by the cross referencing system of Quarto.
# Get a string suitable for inclusion inline in R Markdown with `r eq__(eq1)`
# (inside Markdown text and without the dollar signs around it)
# For inline equations in a Markdown text, you are better to use `r eq_(eq1)`
if (interactive())
eq_(eq1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.