Skip to content

Commit fd4219a

Browse files
committed
fix indentation
1 parent 63e02bf commit fd4219a

File tree

2 files changed

+61
-48
lines changed

2 files changed

+61
-48
lines changed

R/helpers-ppc.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ ppc_group_data <- function(y, yrep, group, stat = NULL) {
234234
# grouping vars. It summarising path, it has one grouping var.
235235
}
236236

237-
# check if x consists of whole numbers (very close to integers)
237+
# Check if x consists of whole numbers (very close to integers)
238+
# Implementation here follows example ?integer
238239
is_whole_number <- function(x, tol = .Machine$double.eps) {
239240
if (!is.numeric(x)) {
240241
FALSE
@@ -243,7 +244,8 @@ is_whole_number <- function(x, tol = .Machine$double.eps) {
243244
}
244245
}
245246

246-
# check if all values in x are whole numbers or counts (non-negative whole numbers)
247+
# Check if all values in x are whole numbers or counts (non-negative whole
248+
# numbers)
247249
all_whole_number <- function(x, ...) {
248250
all(is_whole_number(x, ...))
249251
}

R/ppc-discrete.R

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
#'
3131
#' @template return-ggplot
3232
#'
33-
#' @details For all of these plots \code{y} and \code{yrep} must be
34-
#' integers, although they need not be integers in the strict sense
35-
#' of \R's \code{\link{integer}} type. For rootogram plots \code{y}
33+
#' @details For all of these plots \code{y} and \code{yrep} must be
34+
#' integers, although they need not be integers in the strict sense
35+
#' of \R's \code{\link{integer}} type. For rootogram plots \code{y}
3636
#' and \code{yrep} must also be non-negative.
3737
#'
3838
#' @section Plot Descriptions:
@@ -101,28 +101,37 @@ ppc_bars <-
101101
fatten = 3,
102102
freq = TRUE) {
103103

104-
check_ignored_arguments(...)
105-
y <- validate_y(y)
106-
yrep <- validate_yrep(yrep, y)
107-
if (!all_whole_number(y))
108-
stop("ppc_bars expects 'y' to be discrete.")
109-
if (!all_whole_number(yrep))
110-
stop("ppc_bars expects 'yrep' to be discrete.")
111-
112-
alpha <- (1 - prob) / 2
113-
probs <- sort(c(alpha, 0.5, 1 - alpha))
114-
yrep_data <- ppc_bars_yrep_data(y, yrep, probs = probs, freq = freq, group = NULL)
115-
.ppc_bars(
116-
y_data = data.frame(y = y),
117-
yrep_data,
118-
grouped = FALSE,
119-
facet_args = list(),
120-
width = width,
121-
size = size,
122-
fatten = fatten,
123-
freq = freq
124-
)
104+
check_ignored_arguments(...)
105+
y <- validate_y(y)
106+
yrep <- validate_yrep(yrep, y)
107+
if (!all_whole_number(y)) {
108+
stop("ppc_bars expects 'y' to be discrete.")
125109
}
110+
if (!all_whole_number(yrep)) {
111+
stop("ppc_bars expects 'yrep' to be discrete.")
112+
}
113+
114+
alpha <- (1 - prob) / 2
115+
probs <- sort(c(alpha, 0.5, 1 - alpha))
116+
yrep_data <- ppc_bars_yrep_data(
117+
y,
118+
yrep,
119+
probs = probs,
120+
freq = freq,
121+
group = NULL
122+
)
123+
124+
.ppc_bars(
125+
y_data = data.frame(y = y),
126+
yrep_data,
127+
grouped = FALSE,
128+
facet_args = list(),
129+
width = width,
130+
size = size,
131+
fatten = fatten,
132+
freq = freq
133+
)
134+
}
126135

127136

128137
#' @rdname PPC-discrete
@@ -142,29 +151,31 @@ ppc_bars_grouped <-
142151
fatten = 3,
143152
freq = TRUE) {
144153

145-
check_ignored_arguments(...)
146-
y <- validate_y(y)
147-
yrep <- validate_yrep(yrep, y)
148-
group <- validate_group(group, y)
149-
if (!all_whole_number(y))
150-
stop("ppc_bars_grouped expects 'y' to be discrete.")
151-
if (!all_whole_number(yrep))
152-
stop("ppc_bars_grouped expects 'yrep' to be discrete.")
153-
154-
alpha <- (1 - prob) / 2
155-
probs <- sort(c(alpha, 0.5, 1 - alpha))
156-
yrep_data <- ppc_bars_yrep_data(y, yrep, probs, freq = freq, group = group)
157-
.ppc_bars(
158-
y_data = data.frame(y, group),
159-
yrep_data,
160-
grouped = TRUE,
161-
facet_args = facet_args,
162-
width = width,
163-
size = size,
164-
fatten = fatten,
165-
freq = freq
166-
)
154+
check_ignored_arguments(...)
155+
y <- validate_y(y)
156+
yrep <- validate_yrep(yrep, y)
157+
group <- validate_group(group, y)
158+
if (!all_whole_number(y)) {
159+
stop("ppc_bars_grouped expects 'y' to be discrete.")
167160
}
161+
if (!all_whole_number(yrep)) {
162+
stop("ppc_bars_grouped expects 'yrep' to be discrete.")
163+
}
164+
165+
alpha <- (1 - prob) / 2
166+
probs <- sort(c(alpha, 0.5, 1 - alpha))
167+
yrep_data <- ppc_bars_yrep_data(y, yrep, probs, freq = freq, group = group)
168+
.ppc_bars(
169+
y_data = data.frame(y, group),
170+
yrep_data,
171+
grouped = TRUE,
172+
facet_args = facet_args,
173+
width = width,
174+
size = size,
175+
fatten = fatten,
176+
freq = freq
177+
)
178+
}
168179

169180

170181
#' @rdname PPC-discrete

0 commit comments

Comments
 (0)