table.Drawdowns <- function (R, top = 5, digits = 4) 
{
    R = checkData(R[, 1, drop = FALSE])
    R = na.omit(R)

    #############################  case 0
    if (!any(R<0)) 

    {
      resultPrepare <- data.frame(From=1, Trough=1, To=1, Depth=1, Length=1, 
        "To Trough"=1, Recovery=1)
      result <- resultPrepare[-1,]
      warning(paste("Only ", 0, " available in the data.", 
            sep = ""))
      return(result)  
    } #     if (!any(R<0)) 
    ############################# end case 0

    x = sortDrawdowns(findDrawdowns(R))
    ndrawdowns = sum(x$return < 0)
    if (ndrawdowns < top) {
        warning(paste("Only ", ndrawdowns, " available in the data.", 
            sep = ""))
        top = ndrawdowns
    }
    result = data.frame(time(R)[x$from[1:top]], time(R)[x$trough[1:top]], 
        time(R)[x$to[1:top]], base::round(x$return[1:top], digits), 
        x$length[1:top], x$peaktotrough[1:top], ifelse(is.na(time(R)[x$to[1:top]]), 
            NA, x$recovery[1:top]))
    colnames(result) = c("From", "Trough", "To", "Depth", "Length", 
        "To Trough", "Recovery")
    subset(result, Depth < 0)
    result
} # table.Drawdowns