R/getLeadingPlayers.R

#' See which players lead a stat
#' 
#' Extract common mob names from a list of mob stats. Uses \code{strings.entities} for 
#' substitutions of some mob names.
#' @keywords playerstats
#' @param playerstats The player stat from which the leading players should be calculated, like \code{entities},
#' \code{items} etc.
#' @param dataset Dataset of summary stats like \code{mobStats} or \code{itemStats}
#' @param trailing If \code{TRUE}, the trailing players are returned instead of the leading players
#' @return Vector names
#' @import stringr
#' @export
#' @note Required to produce \code{mobStats}, see \link[wurstmineR]{getMobStats}
#' @examples
#' \dontrun{
#' getLeadingPlayers(mobStats, entities)
#' }
getLeadingPlayers <- function(dataset, playerstats = NULL, trailing = FALSE){
  maxPlayers <- lapply(dataset$stat, function(stat){
    if (!trailing){
      players  <- playerstats[playerstats[[stat]] == max(playerstats[[stat]]), "player"]
    } else {
      players  <- playerstats[playerstats[[stat]] == min(playerstats[[stat]]), "player"]
    }
    players  <- stringr::str_join(players, collapse=" and ")
  })
  maxPlayers <- unlist(maxPlayers)
  return(maxPlayers)
}
jemus42/wurstmineR documentation built on May 19, 2019, 4:03 a.m.