评估存储在R-MarkDown中R对象中的HTML脚本

发布于 2025-01-26 15:01:58 字数 802 浏览 0 评论 0原文

rmarkDown中,如何实现/评估一些html存储在r字符对象中的代码?

如果我将代码明确粘贴为纯文本,则可以按预期工作,例如,详细信息> smumary> show/hide。</summary> woryext&lt ext</delect> 。

但是,我需要从R对象进行评估。例如,如何评估text对象的内容:text< - '<详细信息>摘要> show/hide。</summary> woryext> /代码>?

以下是reprex。

谢谢,艾哈迈德

---
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
     ``` 

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>'?

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
     ``` 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

镜花水月 2025-02-02 15:01:58

您可以在代码块中使用resulte ='asis'

---
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)
``

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)
``

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文