r - 如何在 RStudio 标记选项卡中设置输出样式
问题描述
各国的帮助?rstudioapi::sourceMarkers
:
请注意,如果消息字段属于“html”类(即继承(消息,“html”)== TRUE),则其内容将被视为 HTML。
但是,在运行以下代码时,文本按原样评估,而不是 html。
foo <- shiny::HTML('<div style="color:red;">I am red</div>')
bar <- shiny::HTML('<p style="color:red;">I am red</p>')
inherits(foo, "html")
#> [1] TRUE
inherits(bar, "html")
#> [1] TRUE
markers <- list(
list(
type = "error",
file = getwd(),
line = 145,
column = 1,
message = foo),
list(
type = "info",
file = getwd(),
line = 145,
column = 1,
message = bar))
rstudioapi::sourceMarkers(name = "Test Name", markers)
编辑
能够追踪问题并在 rstudio 提交错误报告
解决方案
只要这个错误在 RStudio 中没有解决,就可以很容易地使用数据框而不是嵌套列表来实现 html 评估:
bar <- '<p style="color:green;">I am green</p>'
markers <- data.frame(
type = c("error", "info"),
file = getwd(),
line = 145:146,
column = 1,
message = c(foo, bar))
attr(markers$message, which = "class") <- c("html", "character")
inherits(markers$message, "html")
#> TRUE
rstudioapi::sourceMarkers(name = "Test Name", markers)
推荐阅读
- r - 如何知道向量是否由相同的元素组成?
- c++ - C ++中的计时计时器加倍
- java - 我的运动冻结了,我不明白为什么
- amazon-web-services - 如何强制删除 S3 存储桶中的所有对象版本,然后最终使用 aws-sdk-go 删除整个存储桶?
- docker - docker 需要虚拟化
- java - 如何在 php 上读取 Java 提交的数据?
- python - FFT 图像的 IFFT 导致原始图像出现奇怪的上下重叠
- python - Python - 将联系人保存到通讯录并打印通讯录
- node.js - NodeJS rhea AMQP 客户端的故障转移
- javascript - 在 Kattis 挑战中获得输入 - readline js