In my code I am checking a condition and I'd like R markdown to show an image when that condition is TRUE. Here is what I have
```{r}
if (LOGICAL.Condition)
{
cat("<img src='http://imgc.allpostersimages.com/images/P-473-488-90/60/6071/B4XD100Z/posters/now-stop-and-hammer-time.jpg'>")
}
```
The output of R that shows up on my HTML page is a text as bellow but I want it to be an image
## <img src='http://imgc.allpostersimages.com/images/P-473-488-90/60/6071/B4XD100Z/posters/now-stop-and-hammer-time.jpg'>
To transform your markdown file into an HTML, PDF, or Word document, click the “Knit” icon that appears above your file in the scripts editor. A drop down menu will let you select the type of output that you want. When you click the button, rmarkdown will duplicate your text in the new file format.
in HTML will appear as <div class=Heading 1> Markdown also allows for raw HTML. There is no need to put any syntax around the code, but it needs to stand alone in the source document with no content above or below. A good example of using raw HTML in a Markdown document is when embedding a Youtube video.
For any markup that is not covered by Markdown's syntax, you simply use HTML itself. There's no need to preface it or delimit it to indicate that you're switching from Markdown to HTML; you just use the tags. The only restrictions are that block-level HTML elements — e.g. <div> , <table> , <pre> , <p> , etc.
If you prefer to use the console by default for all your R Markdown documents (restoring the behavior in previous versions of RStudio), you can make Chunk Output in Console the default: Tools -> Options -> R Markdown -> Show output inline for all R Markdown documents .
Option asis
will simply write the raw results from R into the output document (which is what you'd like). Otherwise it throws that ##
in front.
```{r results="asis"}
if (LOGICAL.Condition)
{
cat("<img src='http://imgc.allpostersimages.com/images/P-473-488-90/60/6071/B4XD100Z/posters/now-stop-and-hammer-time.jpg'>")
}
```
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With