r语言 - 如何使用 sprintf 显示字符串"t"?



我有一个算法来识别.txt文件中使用的分隔符。我想输出使用cat()找到的分隔符。我正在使用%ssprintf()无效。

current.sep = "t"
cat(sprintf("Found separator : %s. n", current.sep))
## Found separator :    .
cat(sprintf("Found separator : %s. n", "current.sep"))
## Found separator : current.sep. 
## I want:
## Found separator : t. 
print_separator <- function(separator) {
    expr <- deparse(paste0("Found separator : ", separator, "."))
    cat(substr(expr, 2, nchar(expr) - 1))
}
print_separator(current.sep)
## Found separator : t.

最新更新