首页 > 解决方案 > 如何在 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 提交错误报告

标签: rrstudiorstudioapi

解决方案


只要这个错误在 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)

在此处输入图像描述


推荐阅读