Skip to content

Error catching for legend.position and legend.justification #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/theme-elements.r
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ el_def <- function(class = NULL, inherit = NULL, description = NULL) {
legend.title.align = el_def("character"),
legend.position = el_def("character"), # Need to also accept numbers
legend.direction = el_def("character"),
legend.justification = el_def("character"),
legend.justification = el_def("character"), # Need to also accept numbers
legend.box = el_def("character"),
legend.box.just = el_def("character"),

Expand Down
10 changes: 8 additions & 2 deletions R/theme.r
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ add_theme <- function(t1, t2, t2name) {
# The other form will simply drop NULL values
t1[item] <- list(x)
}

# Update inherited items
for (item in names(t2)) {
t1[[item]] <- calc_element(item, t1)
Expand Down Expand Up @@ -542,6 +542,12 @@ calc_element <- function(element, theme, verbose = FALSE) {
# it is of the class specified in .element_tree
if (!is.null(theme[[element]]) &&
!inherits(theme[[element]], .element_tree[[element]]$class)) {
if (element != "legend.position" && element != "legend.justification") {
stop(element, " should have class ", .element_tree[[element]]$class)
}
}

if ((element == "legend.position" || element == "legend.justification") && (class(theme[[element]])[1] != "character" && class(theme[[element]])[1] != "numeric")) {
stop(element, " should have class ", .element_tree[[element]]$class)
}

Expand Down Expand Up @@ -578,7 +584,7 @@ combine_elements <- function(e1, e2) {

# If e1 is NULL or element_blank, inherit everything
if (is.null(e1) || inherits(e1, "element_blank")) {e1 <- e2}

# If e1 is not NULL or blank and e2 is element_blank, inherit everything from root
if ((!is.null(e1) || !inherits(e1, "element_blank")) && (is.null(e2) || inherits(e2, "element_blank"))) {
e3 <- base_class(e1)
Expand Down