代码之家  ›  专栏  ›  技术社区  ›  Sharedobe

用stop()终止exectuion,但不在r[重复]中引发“错误”消息

  •  0
  • Sharedobe  · 技术社区  · 6 年前

    my_update_function <- function () {
      df <- data  # get data 
      if (nrow(df) == 0) {
       stop('\r no new data found')
       }
       else {
       # do some updates
       }
    }
    

    电流输出:

    我的预期输出:

    1 回复  |  直到 6 年前
        1
  •  0
  •   Sharedobe    6 年前

    Stop an R program without error

    if (nrow(new_data) == 0) {
        message(log_date, " - ","no new_data is found ")
        opt <- options(show.error.messages=FALSE)
        on.exit(options(opt))
        stop()
    
    }
    else { # DO SOMETHING ELSE
    }