【问题标题】:How to style output in RStudio Markers tab如何在 RStudio 标记选项卡中设置输出样式
【发布时间】:2021-02-22 20:10:00
【问题描述】:

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

编辑

能够追踪问题并filed a bug report at rstudio

【问题讨论】:

    标签: r rstudio rstudioapi


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-09
      • 1970-01-01
      • 2012-10-28
      • 2012-05-04
      • 1970-01-01
      • 2016-12-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多