Skip to content

Commit

Permalink
Remove unnecessary checks on length of pars
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaulrich committed Aug 5, 2024
1 parent 77f8144 commit 2c072bf
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ chart.lines <- function(x,
if(is.null(col))
col <- xx$Env$theme$col

if(length(lty) < NCOL(x)) lty <- rep(lty, length.out = NCOL(x))
if(length(lwd) < NCOL(x)) lwd <- rep(lwd, length.out = NCOL(x))
if(length(col) < NCOL(x)) col <- rep(col, length.out = NCOL(x))
# ensure pars have ncol(x) elements
lty <- rep(lty, length.out = NCOL(x))
lwd <- rep(lwd, length.out = NCOL(x))
col <- rep(col, length.out = NCOL(x))

for(i in NCOL(x):1) {
# x-coordinates for this column
Expand Down Expand Up @@ -247,10 +248,14 @@ plot.xts <- function(x,
legend.loc=NULL,
extend.xaxis=FALSE){

# recycle inputs
if(length(lty) < ncol(x)) lty <- rep(lty, length.out = ncol(x))
if(length(lwd) < ncol(x)) lwd <- rep(lwd, length.out = ncol(x))
if(length(col) < ncol(x)) col <- rep(col, length.out = ncol(x))
# check for colorset or col argument
if(hasArg("colorset")) {
col <- eval.parent(plot.call$colorset)
}
# ensure pars have ncol(x) elements
col <- rep(col, length.out = NCOL(x))
lty <- rep(lty, length.out = NCOL(x))
lwd <- rep(lwd, length.out = NCOL(x))

# Small multiples with multiple pages behavior occurs when multi.panel is
# an integer. (i.e. multi.panel=2 means to iterate over the data in a step
Expand Down Expand Up @@ -360,11 +365,6 @@ plot.xts <- function(x,
# lines of margin to the 4 sides of the plot: c(bottom, left, top, right)
cs$Env$mar <- if (hasArg("mar")) eval.parent(plot.call$mar) else c(3,2,0,2)

# check for colorset or col argument
# if col has a length of 1, replicate to NCOL(x) so we can keep it simple
# and color each line by its index in col
if(hasArg("colorset")) col <- eval.parent(plot.call$colorset)
if(length(col) < ncol(x)) col <- rep(col, length.out = ncol(x))
cs$Env$format.labels <- format.labels
cs$Env$yaxis.ticks <- yaxis.ticks
cs$Env$major.ticks <- if (isTRUE(major.ticks)) "auto" else major.ticks
Expand All @@ -373,11 +373,6 @@ plot.xts <- function(x,
cs$Env$grid.ticks.lwd <- grid.ticks.lwd
cs$Env$grid.ticks.lty <- grid.ticks.lty
cs$Env$type <- type

# if lty or lwd has a length of 1, replicate to NCOL(x) so we can keep it
# simple and draw each line with attributes by index
if(length(lty) < ncol(x)) lty <- rep(lty, length.out = ncol(x))
if(length(lwd) < ncol(x)) lwd <- rep(lwd, length.out = ncol(x))
cs$Env$lty <- lty
cs$Env$lwd <- lwd

Expand Down

0 comments on commit 2c072bf

Please sign in to comment.