Skip to content

Commit 7c0abec

Browse files
committed
apply linting where appropriate
1 parent 31b557f commit 7c0abec

17 files changed

Lines changed: 1037 additions & 955 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ docs
88
inst/doc
99
.DS_Store
1010
/doc/
11-
/Meta/
11+
/Meta/
12+
.lintr

R/graphs.R

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ plot_vintages <- function(
133133
"The 'type' argument must be either 'line', 'point', 'bar' or 'boxplot'."
134134
)
135135
}
136-
137-
136+
138137
# Check 'time_col' is column name of 'df'
139138
if (!time_col %in% colnames(df)) {
140139
rlang::abort(
@@ -151,7 +150,6 @@ plot_vintages <- function(
151150
df <- vintages_long(df, keep_na = FALSE)
152151
}
153152

154-
155153
# Check 'dim_col' is column name of 'df'
156154
if (!dim_col %in% colnames(df)) {
157155
rlang::abort(
@@ -162,8 +160,6 @@ plot_vintages <- function(
162160
)
163161
)
164162
}
165-
166-
167163

168164
# Check that 'time_col' is of date format
169165
if (!inherits(df[[time_col]], "Date")) {
@@ -212,7 +208,9 @@ plot_vintages <- function(
212208
if (n == 1L) {
213209
if (type == "line") {
214210
p <- p +
215-
ggplot2::geom_line(ggplot2::aes(x = !!time_col, y = .data$value), data = df) +
211+
ggplot2::geom_line(
212+
ggplot2::aes(x = !!time_col, y = .data$value), data = df
213+
) +
216214
scale_color_reviser()
217215
} else if (type == "point") {
218216
p <- p +
@@ -271,7 +269,9 @@ plot_vintages <- function(
271269
} else if (type == "boxplot") {
272270
p <- p +
273271
ggplot2::geom_boxplot(
274-
ggplot2::aes(x = !!time_col, y = .data$value, fill = factor(!!time_col)),
272+
ggplot2::aes(
273+
x = !!time_col, y = .data$value, fill = factor(!!time_col)
274+
),
275275
data = df
276276
) +
277277
scale_fill_reviser() +
@@ -304,12 +304,12 @@ plot_vintages <- function(
304304
}
305305

306306
#' Plot Revision Model Results
307-
#'
307+
#'
308308
#' @param x An object of class 'revision_model'
309309
#' @param state String. The name of the state to visualize.
310310
#' @param type String. Type of estimate: "filtered" or "smoothed".
311311
#' @param ... Additional arguments passed to theme_reviser.
312-
#'
312+
#'
313313
#' @keywords internal
314314
#' @noRd
315315
plot.revision_model <- function(x, state = NULL, type = "filtered", ...) {
@@ -319,45 +319,47 @@ plot.revision_model <- function(x, state = NULL, type = "filtered", ...) {
319319
state <- x$states[x$states$filter == type, ]$state[1]
320320
rlang::warn(paste("No state specified. Defaulting to first state:", state))
321321
}
322-
322+
323323
# Filter data
324324
plot_data <- x$states[x$states$state == state & x$states$filter == type, ]
325-
325+
326326
if (nrow(plot_data) == 0) {
327327
rlang::abort(paste("State", state, "not found in model results."))
328328
}
329329
# Setup Aesthetics (Unified Legend)
330330
pal <- colors_reviser()
331331
col_values <- c("in_sample" = pal[1], "out_of_sample" = pal[2])
332332
line_values <- c("in_sample" = "solid", "out_of_sample" = "solid")
333-
label_values <- c("in_sample" = "In-sample", "out_of_sample" = "Out-of-sample")
334-
333+
label_values <- c(
334+
"in_sample" = "In-sample", "out_of_sample" = "Out-of-sample"
335+
)
336+
335337
# Build Plot
336338
# Split samples
337339
in_sample_data <- plot_data[plot_data$sample == "in_sample", ]
338340
oos_data <- plot_data[plot_data$sample == "out_of_sample", ]
339-
341+
340342
p <- ggplot2::ggplot() +
341-
343+
342344
# ---- In-sample: always line + ribbon ----
343-
ggplot2::geom_ribbon(
344-
data = in_sample_data,
345-
ggplot2::aes(
346-
x = .data$time, ymin = .data$lower, ymax = .data$upper, fill = sample
347-
),
348-
alpha = 0.2
349-
) +
345+
ggplot2::geom_ribbon(
346+
data = in_sample_data,
347+
ggplot2::aes(
348+
x = .data$time, ymin = .data$lower, ymax = .data$upper, fill = sample
349+
),
350+
alpha = 0.2
351+
) +
350352
ggplot2::geom_line(
351353
data = in_sample_data,
352354
ggplot2::aes(
353355
x = .data$time, y = .data$estimate, color = sample, linetype = sample
354356
),
355357
linewidth = 0.8
356358
)
357-
359+
358360
# ---- Out-of-sample: branch on length ----
359361
if (nrow(oos_data) == 1) {
360-
362+
361363
p <- p +
362364
ggplot2::geom_crossbar(
363365
data = oos_data,
@@ -379,9 +381,7 @@ plot.revision_model <- function(x, state = NULL, type = "filtered", ...) {
379381
),
380382
size = 2
381383
)
382-
383384
} else {
384-
385385
p <- p +
386386
ggplot2::geom_ribbon(
387387
data = oos_data,
@@ -398,7 +398,7 @@ plot.revision_model <- function(x, state = NULL, type = "filtered", ...) {
398398
linewidth = 0.8
399399
)
400400
}
401-
401+
402402
# ---- Scales & theme ----
403403
p <- p +
404404
ggplot2::scale_fill_manual(
@@ -420,10 +420,8 @@ plot.revision_model <- function(x, state = NULL, type = "filtered", ...) {
420420
color = "Sample", fill = "Sample", linetype = "Sample"
421421
) +
422422
ggplot2::ylab("")
423-
423+
424424
p
425-
426-
427425
return(p)
428426
}
429427

0 commit comments

Comments
 (0)