2016-10-23 4 views
0

.txt 파일에서 사용되는 구분 기호를 식별하는 알고리즘이 있습니다. cat()을 사용하여 발견 된 구분 기호를 출력하고 싶습니다. 을 sprintf()과 함께 사용하고 있습니다.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. 
관련 문제