当打印到控制台或返回一个字符串时,我得到了这个:
[1] "Please choose species to add data for".
我有这个恼人的:[1]
,在字符串的开头,我无法摆脱它。
这是我的代码,例如,它用闪亮的包编写,输出在GUI中:
DataSets <<- input$newfile
if (is.null(DataSets))
return("Please choose species to add data for")
答案 0 :(得分: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
答案 1 :(得分: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