2014-02-25 4 views
2

콘솔에 인쇄하거나 문자열을 반환 할 때 나는이 얻을 : 나는 그것을 제거 할 수없는 문자열의 시작 부분에서, [1] : "[1]"을 제거하려면 어떻게해야합니까?

[1] "Please choose species to add data for".

내가이 짜증나 있습니다.

여기 예를 들어, 내 코드입니다, 그것은 반짝 패키지 작성 및 출력은 GUI에있어 : ​​

DataSets <<- input$newfile 
    if (is.null(DataSets)) 
    return("Please choose species to add data for") 

답변

5

cat으로이에 대한

> print("Please choose species to add data for") 
[1] "Please choose species to add data for" 
> cat("Please choose species to add data for") 
Please choose species to add data for 
사용하지 마십시오
+0

와우 너무 간단합니다, 감사합니다! – dmitriy

8

cat합니다. 그것은 message를 사용하는 것이 좋습니다 : 그러나

fun <- function(DataSets) { 
    if (is.null(DataSets)) { 
    message("Please choose species to add data for") 
    invisible(NULL) 
    } 
} 

fun(NULL) 
#Please choose species to add data for 

, 내가 경고 반환 :

fun <- function(DataSets) { 
    if (is.null(DataSets)) { 
    warning("Please choose species to add data for") 
    invisible(NULL) 
    } 
} 

fun(NULL) 
#Warning message: 
# In fun(NULL) : Please choose species to add data for 

또는 오류 :

fun <- function(DataSets) { 
    if (is.null(DataSets)) { 
    stop("Please choose species to add data for") 
    } 
} 

fun(NULL) 
#Error in fun(NULL) : Please choose species to add data for 
관련 문제