我想在某些单元格中用红色printed印刷标题。
X <- "\u2718"
redX <- paste0("\033[0;31m", X, "\033[0m")
cat(redX)
打印我想要的单个字符。
tibble::tibble(X)
适用于默认颜色的字符。
但是,
tibble::tibble(redX)
给予:
# A tibble: 1 x 1
redX
<chr>
1 "\u001b[0;31m✘\u001b[0m"
因此,颜色编码无法重新识别。
使用蜡笔也明显失败:
tibble::tibble(intToUtf8(10008)) # works for default color
tibble::tibble(crayon::red(intToUtf8(10008))) # doesn't work for red
如果我使用支柱,我会得到着色,但unicode无法逃脱:
pillar_shaft.character <- function(x, ...){
out <- pillar::style_na(format(x))
pillar::new_pillar_shaft_simple(out, align = "right")
}
pillar::pillar_shaft(c("\u2718", intToUtf8(10008)))
可复制的示例:
redX <- paste0("\033[0;31m", X, "\033[0m")
X <- "\u2718"
cat(redX) # works
cat(X) # works
tibble::tibble(X) # works for default color
tibble::tibble(redX) # doesn't work
tibble::tibble(intToUtf8(10008)) # works for default color
tibble::tibble(crayon::red(intToUtf8(10008))) # doesn't work
pillar_shaft.character <- function(x, ...){
out <- pillar::style_na(format(x))
pillar::new_pillar_shaft_simple(out, align = "right")
}
pillar::pillar_shaft(c("\u2718", intToUtf8(10008))) # gives color, but unicode character is not recognized