2

When printing to the console or return a string I get this:

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

I have this annoying: [1], in the beginning of the string that I can't get rid of it.

Here is my code for example, it's written with shiny package and the output is in the GUI:

  DataSets <<- input$newfile
  if (is.null(DataSets))
  return("Please choose species to add data for")
zx8754
  • 52,746
  • 12
  • 114
  • 209
dmitriy
  • 253
  • 1
  • 17

2 Answers2

9

Don't use cat for this. It's better to use 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

However, I would return a warning:

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

or an error:

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
Roland
  • 127,288
  • 10
  • 191
  • 288
6

With 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
Victorp
  • 13,636
  • 2
  • 51
  • 55