Embedding a variable in rmarkdown output html to allow easy text formatting

I have multiple parameters that I need to analyze and was wanting to embed the variable "Manufacturer" in the html output to allow me to easily control the display color and font size in the rmarkdown output. Any direction you can provide is appreciated.

library(tidyverse, quietly = T)
library(data.table, quietly=T)
library(ggpubr, quietly = T)
library(plotly, quietly = T)
library(htmlTable, quietly = T)
library(kableExtra, quietly = T)
library(XML, quietly = T)
library(methods, quietly = T)

if(HDclass=="1") '<span style="color:red">The drive manufacturer is `r Manufacturer`</span>'

What did you try exactly ? What is not working as you expect ? It seems that you are doing well with your example above.

Few resources:

and all the R Markdown book in general

I had the if statement in a chunk and when I created the case it stripped that out. Pardon me, I'm new to this.

If I try to set up a chunk
{r print-this}
if(HDclass=="1") 'The drive manufacturer is r Manufacturer'

This will just print 'The drive manufacturer is r Manufacturer' in the markdown and not the formatted text. I have tried " ", and combinations of print and cat to try to get it to work. Can you set the print output within a chunk or do you have to use css. I am new, these may be obvious questions.

The above line in the example works as long as it is inline and the reason I want it in the chunk is to use an eval= to determine whether the chunk gets processed to save on a bunch of if statements.


If you want to output text that should be used as Raw markdown and not usual R output, you need to tell knitr about this.

please follow the documentation

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.