Skip to content

Commit ef7ab03

Browse files
init (#450)
1 parent ae2cb18 commit ef7ab03

4 files changed

Lines changed: 11 additions & 11 deletions

File tree

R/by_aesthetics.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ by_col = function(ngrps = 1L, col = NULL, palette = NULL, gradient = NULL, order
6363
"\nFewer colours ", ncolsstr, " provided than than there are groups ",
6464
ngrpsstr, ". Recycling to make up the shortfall."
6565
)
66-
col = rep(col, length.out = ngrps)
66+
col = rep_len(col, ngrps)
6767
}
6868

6969
}
@@ -154,7 +154,7 @@ by_col = function(ngrps = 1L, col = NULL, palette = NULL, gradient = NULL, order
154154
"\nFewer colours ", ncolsstr, " provided than than there are groups ",
155155
ngrpsstr, ". Recycling to make up the shortfall."
156156
)
157-
args = rep(args, length.out = ngrps)
157+
args = rep_len(args, ngrps)
158158
}
159159
}
160160
} else {
@@ -188,7 +188,7 @@ by_col = function(ngrps = 1L, col = NULL, palette = NULL, gradient = NULL, order
188188
"\nFewer colours ", ncolsstr, " provided than than there are groups ",
189189
ngrpsstr, ". Recycling to make up the shortfall."
190190
)
191-
args = rep(args, length.out = ngrps)
191+
args = rep_len(args, ngrps)
192192
}
193193
}
194194
} else {

R/tinyplot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ tinyplot.default = function(
984984
}
985985

986986
# aesthetics by group: col, bg, etc.
987-
ngrps = if (null_by) 1L else if (is.factor(by)) length(levels(by)) else if (by_continuous) 100L else length(unique(by))
987+
ngrps = if (null_by) 1L else if (is.factor(by)) nlevels(by) else if (by_continuous) 100L else length(unique(by))
988988
pch = by_pch(ngrps = ngrps, type = type, pch = pch)
989989
lty = by_lty(ngrps = ngrps, type = type, lty = lty)
990990
lwd = by_lwd(ngrps = ngrps, type = type, lwd = lwd)

R/type_barplot.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ data_barplot = function(width = 5/6, beside = FALSE, center = FALSE, FUN = NULL,
9595
if (!is.factor(datapoints$x)) datapoints$x = factor(datapoints$x)
9696
if (!is.null(xlevels)) {
9797
xlevels = if(is.numeric(xlevels)) levels(datapoints$x)[xlevels] else xlevels
98-
if (any(is.na(xlevels)) || !all(xlevels %in% levels(datapoints$x))) warning("not all 'xlevels' correspond to levels of 'x'")
98+
if (anyNA(xlevels) || !all(xlevels %in% levels(datapoints$x))) warning("not all 'xlevels' correspond to levels of 'x'")
9999
datapoints$x = factor(datapoints$x, levels = xlevels)
100100
}
101101
if (!is.null(xaxlabels)) levels(datapoints$x) <- xaxlabels
@@ -118,7 +118,7 @@ data_barplot = function(width = 5/6, beside = FALSE, center = FALSE, FUN = NULL,
118118
z[floor(mid) + 1L] = (mid - floor(mid)) * z[floor(mid) + 1L]
119119
sum(z[0L:floor(mid) + 1L], na.rm = TRUE)
120120
}
121-
if (is.null(xlim)) xlim = c(1, length(levels(datapoints$x))) + c(-0.5, 0.5) * width
121+
if (is.null(xlim)) xlim = c(1, nlevels(datapoints$x)) + c(-0.5, 0.5) * width
122122
if (is.null(ylim)) ylim = if (beside || length(unique(datapoints$by)) == 1L) {
123123
c(pmin(0, min(datapoints$y, na.rm = TRUE) * 1.02), pmax(0, max(datapoints$y, na.rm = TRUE) * 1.02))
124124
} else {
@@ -143,8 +143,8 @@ data_barplot = function(width = 5/6, beside = FALSE, center = FALSE, FUN = NULL,
143143
datapoints = lapply(sdat, function(df) {
144144

145145
df = df[order(df$x), , drop = FALSE]
146-
nx = length(levels(df$x))
147-
nb = length(levels(df$by))
146+
nx = nlevels(df$x)
147+
nb = nlevels(df$by)
148148

149149
if (beside) {
150150
xl = as.numeric(df$x) - width/2 + (as.numeric(df$by) - 1) * width/nb * as.numeric(!facet_by)

R/type_spineplot.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ data_spineplot = function(off = NULL, breaks = NULL, xlevels = xlevels, ylevels
136136
x.categorical = is.factor(datapoints$x)
137137
if (!is.null(xlevels) && x.categorical) {
138138
xlevels = if(is.numeric(xlevels)) levels(datapoints$x)[xlevels] else xlevels
139-
if (any(is.na(xlevels)) || !all(xlevels %in% levels(datapoints$x))) warning("not all 'xlevels' correspond to levels of 'x'")
139+
if (anyNA(xlevels) || !all(xlevels %in% levels(datapoints$x))) warning("not all 'xlevels' correspond to levels of 'x'")
140140
datapoints$x = factor(datapoints$x, levels = xlevels)
141141
if (x_by) datapoints$by = datapoints$x
142142
}
143143
if (!is.null(ylevels)) {
144144
ylevels = if(is.numeric(ylevels)) levels(datapoints$y)[ylevels] else ylevels
145-
if (any(is.na(ylevels)) || !all(ylevels %in% levels(datapoints$y))) warning("not all 'ylevels' correspond to levels of 'y'")
145+
if (anyNA(ylevels) || !all(ylevels %in% levels(datapoints$y))) warning("not all 'ylevels' correspond to levels of 'y'")
146146
datapoints$y = factor(datapoints$y, levels = ylevels)
147147
if (y_by) datapoints$by = datapoints$y
148148
}
@@ -243,7 +243,7 @@ data_spineplot = function(off = NULL, breaks = NULL, xlevels = xlevels, ylevels
243243

244244
# catch for x_by / y/by
245245
if (isTRUE(x_by)) datapoints$by = factor(rep(xaxlabels, each = ny)) # each x label extends over ny rows
246-
if (isTRUE(y_by)) datapoints$by = factor(rep(yaxlabels, length.out = nrow(datapoints)))
246+
if (isTRUE(y_by)) datapoints$by = factor(rep_len(yaxlabels, nrow(datapoints)))
247247

248248
## grayscale flag
249249
grayscale = null_by && is.null(palette) && is.null(.tpar[["palette.qualitative"]])

0 commit comments

Comments
 (0)