Skip to content

Commit

Permalink
Evaluate main header and x-axis in local envir
Browse files Browse the repository at this point in the history
This avoids the potential to overwrite variables in 'Env' while
evaluating the expression. For example, the 'main_xaxis_expr' was
overwriting the 'type' value that is passed to chart.lines().
  • Loading branch information
joshuaulrich committed Oct 13, 2023
1 parent 0b7fbda commit d467ea6
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,7 @@ new.replot_xts <- function(panel=1,asp=1,xlim=c(1,10),ylim=list(structure(c(1,10

# main plot header
Env$main_header_expr <- expression({
local({
text(x = xlim[1],
y = 0.98,
labels = main,
Expand All @@ -1081,10 +1082,12 @@ new.replot_xts <- function(panel=1,asp=1,xlim=c(1,10),ylim=list(structure(c(1,10
col = theme$labels,
font = NULL)
}
}, new.env(TRUE, Env))
})

# main plot x-axis
Env$main_xaxis_expr <- expression({
local({
# add observation level ticks on x-axis if < 400 obs.
if (NROW(xdata[xsubset]) < 400) {
axis(1,
Expand Down Expand Up @@ -1135,6 +1138,7 @@ new.replot_xts <- function(panel=1,asp=1,xlim=c(1,10),ylim=list(structure(c(1,10
col = theme$labels,
col.axis = theme$labels)
}
}, new.env(TRUE, Env))
})

# panel functionality
Expand Down

0 comments on commit d467ea6

Please sign in to comment.