2016-10-23 16 views
0

我有一个算法来识别在.txt文件中使用的分隔符。我想输出使用cat()找到的分隔符。我使用%ssprintf()无济于事。如何使用sprintf显示字符串“ t”?

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. 
+1

这...是显示它? '##找到分隔符:.'(注释去掉了空格,但是w/e)有一个'\ t',不是吗? –

回答

1
print_separator <- function(separator) { 

    expr <- deparse(paste0("Found separator : ", separator, ".")) 
    cat(substr(expr, 2, nchar(expr) - 1)) 

} 

print_separator(current.sep) 
## Found separator : \t.