Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Evaluate html script stored in R object in R-markdown

In Rmarkdown, how can I implement/evaluate some HTML code stored in an R character object?

If I explicitly paste the code as plain text, it works as expected e.g. <details><summary>Show/hide.</summary>SomeText</details>.

However, I need to evaluate this from an R object; e.g. how to evaluate the content of the Text object: Text <- '<details><summary>Show/hide.</summary>SomeText</details>'?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Below is a reprex.

Thanks, Ahmed

---
title: "Literature notes"
output: 
  html_document:
    #code_folding: hide
---

<details><summary>Show/hide.</summary>SomeText</details> # This works

     ```{r, eval=TRUE, echo=F}
     Text <- '<details><summary>Show/hide.</summary>SomeText</details>'
     Text
     ## how to do the same using info stored in 'Text' object
     ``` 

>Solution :

You can use results='asis' in the code chunk:

---
title: "Literature notes"
output: 
  html_document:
    #code_folding: hide
---


```{r, eval=TRUE, echo=F, results='asis'}
 Text <- '<details><summary>Show/hide.</summary>SomeText</details>'
 cat(Text)
``

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading