Skip to content

Commit

Permalink
fix lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
gogonzo committed Dec 25, 2023
1 parent 15dcd6d commit a1b2080
Show file tree
Hide file tree
Showing 18 changed files with 249 additions and 288 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ TODO
\.xcf
^docs$
^\.github$
.lintr$
4 changes: 1 addition & 3 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
linters: linters_with_defaults(
line_length_linter(100L)
)
exclusions: list(
"data-raw"
)
exclusions: list("data-raw")
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Language: en-US
URL: https://github.com/gogonzo/sport
LazyData: true
RoxygenNote: 7.2.3
Roxygen: list(markdown = TRUE)
Suggests:
dplyr,
knitr,
Expand Down
44 changes: 22 additions & 22 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#' Heat results of Speedway Grand-Prix
#'
#' Actual dataset containing heats results of all Speedway Grand-Prix turnaments
#' \code{gpheats}.
#' `gpheats`.
#'
#' @format A data frame with >19000 rows and 11 variables:
#' \describe{
#' \item{id}{event identifier}
#' \item{season}{year of Grand-Prix, 1995-now}
#' \item{date}{date of turnament}
#' \item{round}{round in season}
#' \item{name}{Turnament name}
#' \item{heat}{heat number, 1-23}
#' \item{field}{number of gate, 1-4}
#' \item{rider}{rider name, string}
#' \item{points}{paints gained, integer}
#' \item{position}{position at finish line, string}
#' \item{rank}{rank at finish line, integer}
#' - `id` - event identifier
#' - `season` - year of Grand-Prix, 1995-now
#' - `date` - date of turnament
#' - `round` - round in season
#' - `name` - Turnament name
#' - `heat` - heat number, 1-23
#' - `field` - number of gate, 1-4
#' - `rider` - rider name, string
#' - `points` - paints gained, integer
#' - `position` - position at finish line, string
#' - `rank` - rank at finish line, integer
#' }
#' @source internal
#' @name gpheats
Expand All @@ -24,19 +24,19 @@ NULL
#' Turnament results of Speedway Grand-Prix
#'
#' Actual dataset containing turnament results of all Speedway Grand-Prix events
#' \code{gpsquads}
#' `gpsquads`
#'
#' @format A data frame with >4000 rows and 9 variables:
#' \describe{
#' \item{id}{event identifier}
#' \item{season}{year of Grand-Prix, 1995-now}
#' \item{date}{date of turnament}
#' \item{place}{stadium of event}
#' \item{round}{round in season}
#' \item{name}{Turnament name}
#' \item{rider}{rider names, 1-6}
#' \item{points}{points gained, integer}
#' \item{classification}{classification after an event}
#' - `id` - event identifier
#' - `season` - year of Grand-Prix, 1995-now
#' - `date` - date of turnament
#' - `place` - stadium of event
#' - `round` - round in season
#' - `name` - Turnament name
#' - `rider` - rider names, 1-6
#' - `points` - points gained, integer
#' - `classification` - classification after an event
#' }
#' @source internal
#' @name gpsquads
Expand Down
30 changes: 15 additions & 15 deletions R/output.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ NULL
#' @param object of class rating
#' @param ... optional arguments
#' @return
#' List with following elements \itemize{
#' \item \code{formula} modeled formula.
#' \item \code{method} type of algorithm used.
#' \item \code{Overall Accuracy} named vector containing players ratings.
#' \item \code{r} data.frame summarized players ratings and model winning probabilities. Probabilities are returned only in models with one variable (ratings) \itemize{
#' \item \code{name} of a player
#' \item \code{r} players ratings
#' \item \code{rd} players ratings deviation
#' \item \code{`Model probability`} mean predicted probability of winning the challenge by the player.
#' \item \code{`True probability`} mean observed probability of winning the challenge by the player.
#' \item \code{`Accuracy`} Accuracy of prediction.
#' \item \code{`pairings`} number of pairwise occurrences.
#' }
#' }
#' List with following elements:
#' - `formula` modeled formula.
#' - `method` type of algorithm used.
#' - `Overall Accuracy` named vector containing players ratings.
#' - `r` data.frame summarized players ratings and model winning probabilities.
#'
#' Probabilities are returned only in models with one variable (ratings):
#' - `name` of a player
#' - `r` players ratings
#' - `rd` players ratings deviation
#' - `Model probability` mean predicted probability of winning the challenge by the player.
#' - `True probability` mean observed probability of winning the challenge by the player.
#' - `Accuracy` Accuracy of prediction.
#' - `pairings` number of pairwise occurrences.
#'
#' @examples
#' model <- glicko_run(
Expand Down Expand Up @@ -141,7 +141,7 @@ plot.rating <- function(x, n = 10, players, ...) {
names(data)[1] <- variable

data <- data[order(data$r, decreasing = TRUE), ][1:n, ]
data[[variable]] <- reorder(data[[variable]], nrow(data):1)
data[[variable]] <- reorder(data[[variable]], rev(seq_len(nrow(data))))
ggplot(data, aes(x = .data[[variable]], y = .data$r)) +
ggtitle("Actual ratings") +
geom_linerange(
Expand Down
8 changes: 4 additions & 4 deletions R/predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' predict(glicko, gpheats[17:20, ])
#' @export
predict.rating <- function(object, newdata, ...) {
if (missing(newdata)) stop("newdata is requested to predict", call. = F)
if (missing(newdata)) stop("newdata is requested to predict", call. = FALSE)
method <- attr(object, "method")
formula <- attr(object, "formula")
all_vars <- all.vars(formula)
Expand Down Expand Up @@ -89,8 +89,8 @@ predict.rating <- function(object, newdata, ...) {
)
}

P <- model$pairs # data.table
P <- P[, Y := ifelse(P > .5, 1, ifelse(P == .5, .5, 0))]
pairs <- model$pairs # data.table
pairs <- pairs[, Y := ifelse(P > .5, 1, ifelse(P == .5, .5, 0))]

return(P)
return(pairs)
}
Loading

0 comments on commit a1b2080

Please sign in to comment.