calc_smo = function(cat_freqlist,
                    sortperspar,
                    smooth = "spline",
                    smoothargs=NULL,
                    smoothrange = NULL) {

  if(length(smooth) == 0) smooth = "spline"
  if (!is.null(smoothrange)) {
      xaxis = smoothrange
  } else {
      xaxis = seq(min(sortperspar), max(sortperspar), 0.01)
  }

  smooth = tolower(smooth)

  # if (!(smooth %in% c("loess", "spline")))
  #   stop("You provided an unknown option for the smooth argument.
  #       \nThe available options are either 'spline' or 'loess'.", call. = FALSE)

  if (smooth == "loess") {
      smoothlist = lapply(cat_freqlist, function(z) {
         y = as.data.frame(z)
         lapply(y, function(x) {
                   smoothcalc = do.call(loess, c(list(x ~ sortperspar), smoothargs))
                   yaxis = predict(smoothcalc, xaxis)
         })
      })
  } else if (smooth == "spline") {
      smoothlist = lapply(cat_freqlist, function(z) {
         y = as.data.frame(z)
         lapply(y, function(x) {
                   smoothcalc = do.call(smooth.spline, c(list(sortperspar, x), smoothargs))
                   yaxis = predict(smoothcalc, xaxis)$y
      })
    })
  }
  smoothdf = lapply(smoothlist, function(x) {do.call(cbind, x)})
  attr(smoothdf, "xaxis") = xaxis
  return(smoothdf = smoothdf)
}
