R/ptfFun.pred.R

Defines functions ptfFun.pred

Documented in ptfFun.pred

#' Prediction of soil hydraulic properties
#'
#' @param ptf.object object of ranger class with the built random forest
#' @param df data.frame with data, specific column names are required. It is advised to use euptfFun.
#'
#' @return a vector of predicted, back transformed values. A data frame, if sets of Mualem-van Genuchten Paraemters, or van Genuchten Parameters are predicted.
#' @export
#'
#' @examples
#' # cf euptfFun
#' load(MVG_PTF01)
#' load(sample_data)
#' ptfFun.pred(ptf.object =MVG_PTF01 , df = sample_data)
#'


ptfFun.pred <- function(ptf.object, df){

 #' @importFrom stats predict

     # thanks to flodel@stackoverflow
     depth <- function(this) ifelse(is.list(this), 1L + max(sapply(this, depth)), 0L)

     if(depth(ptf.object)==5){
         result <-  suppressWarnings(lapply(ptf.object, function(x) {predict(x, data = df)$predictions}) )
     }else{
          result <- predict(ptf.object, data = df)$predictions
     }
return(result)
}
tkdweber/euptf2 documentation built on Jan. 19, 2021, 4:20 p.m.