Reputation: 61
I am trying to insert a greek delta into a covariate label within stargazer. I have tried \Delta but it returns an error about the escape character '\D'. I have attempted with '\', wrapping in '$' and on and on.
What does work is to use the string 'CHG' and then replace all instances of 'CHG' in the html output with Δ.
I have tried one slash, 2, 3, 4. I have tried wrapping in '${ ... }$
#```{r setup, include = FALSE, warning = FALSE, comment = FALSE}
library(dplyr)
library(stringr)
library(tidyr)
library(stargazer)
library(knitr)
x <- rnorm(1000)
y <- rnorm(1000)*x
df <- data.frame(x,y)
model1 <- lm(y~x, data = df)
#```{r Perf1.1, echo = FALSE, warning = FALSE, comment = FALSE, message = FALSE, results='asis'}
stargazer(model1, header=FALSE, type = 'html',
dep.var.labels = "\\Delta y")
Upvotes: 2
Views: 1824
Reputation: 1
I have no idea why but, putting 4 backslashes before any math input worked for me.
Upvotes: 0
Reputation: 21
dep.var.labels = "<strong>Δ</strong> COGS_{t}
The answer above from @HLRA works for HTML code, not latex code. That is, the output of the "out.html" file can show the symbol of \Delta correctly.
But the latex code generated doesn't work as <strong>
is not from the latex language.
Upvotes: 0
Reputation: 53
For some reason, it seems to work when you surround it with (any?) HTML tag. For example, what worked for me applied to your case would be:
dep.var.labels = "<strong>Δ</strong> COGS_{t}",
Upvotes: 0
Reputation: 545865
Backslash is the escape character in R strings. To include it literally you therefore need to … escape it. So, double it up:
dep.var.labels = "\\Delta COGS_{t}",
However, this probably won’t work for HTML output, only for LaTeX output. For HTML, use the corresponding entity, or just use the Unicode character.
Upvotes: 1