diff --git a/R/messages_v4_v3.R b/R/messages_v4_v3.R index 3ce1bef3..be5e6226 100644 --- a/R/messages_v4_v3.R +++ b/R/messages_v4_v3.R @@ -30,43 +30,53 @@ v3_convert2density = function(layer_fun) { } v3_tm_scale_instead_of_style = function(style, scale_fun, vv, layer_fun, arg_list) { - if (scale_fun == "intervals") { - arg_list$old = c("style", arg_list$old) - arg_list$new = c("style", arg_list$new) - } - if (length(arg_list$old)) { - x = if (arg_list$mult) { - paste0(". For small multiples, specify a 'tm_scale_' for each multiple, and put them in a list: '", vv, ".scale = list(, , ...)'") + m = paste0("scale_", scale_fun, "_vv_", vv, "style_", style) + if (!message_thrown(m)) { + if (scale_fun == "intervals") { + arg_list$old = c("style", arg_list$old) + arg_list$new = c("style", arg_list$new) + } + if (length(arg_list$old)) { + x = if (arg_list$mult) { + paste0(". For small multiples, specify a 'tm_scale_' for each multiple, and put them in a list: '", vv, ".scale = list(, , ...)'") + } else { + "" + } + al = do.call(paste, c(mapply(function(x,y) { + if (x == y) paste0("'", x, "'") else paste0("'", x, "' (rename to '", y, "')") + }, arg_list$old, arg_list$new, SIMPLIFY = FALSE), sep = ", ")) + xtra = paste0(" and migrate the argument(s) ", al, " to 'tm_scale_", scale_fun, "()'") } else { - "" + xtra = "" + x = "" } - al = do.call(paste, c(mapply(function(x,y) { - if (x == y) paste0("'", x, "'") else paste0("'", x, "' (rename to '", y, "')") - }, arg_list$old, arg_list$new, SIMPLIFY = FALSE), sep = ", ")) - xtra = paste0(" and migrate the argument(s) ", al, " to 'tm_scale_", scale_fun, "()'") - } else { - xtra = "" - x = "" + + message(paste0("[v3->v4] ", layer_fun, "(): instead of 'style = \"", style, "\"', use '", vv, ".scale = tm_scale_", scale_fun, "()'", xtra, x)) + message_reg(m) } - - message(paste0("[v3->v4] ", layer_fun, "(): instead of 'style = \"", style, "\"', use '", vv, ".scale = tm_scale_", scale_fun, "()'", xtra, x)) + NULL } v3_tm_scale = function(scale_fun, vv, layer_fun, arg_list) { - scale_fun = if (scale_fun == "") { - "tm_scale" - } else { - paste0("tm_scale_", scale_fun) - } - if (length(arg_list$old)) { - x = if (arg_list$mult) { - paste0(". For small multiples, specify a 'tm_scale_' for each multiple, and put them in a list: '", vv, ".scale = list(, , ...)'") + m = paste0("scale_", scale_fun, "_vv_", vv) + + if (!message_thrown(m)) { + scale_fun = if (scale_fun == "") { + "tm_scale" } else { - "" + paste0("tm_scale_", scale_fun) } - - al = v3_list_text(olds = arg_list$old, news = arg_list$new) - message("[v3->v4] ", layer_fun, "(): migrate the argument(s) related to the scale of the visual variable '", vv, "', namely ", al, " to '", vv, ".scale = ", scale_fun, "()'", x) + if (length(arg_list$old)) { + x = if (arg_list$mult) { + paste0(". For small multiples, specify a 'tm_scale_' for each multiple, and put them in a list: '", vv, ".scale = list(, , ...)'") + } else { + "" + } + + al = v3_list_text(olds = arg_list$old, news = arg_list$new) + message("[v3->v4] ", layer_fun, "(): migrate the argument(s) related to the scale of the visual variable '", vv, "', namely ", al, " to '", vv, ".scale = ", scale_fun, "()'", x) + } + message_reg(m) } NULL } diff --git a/R/qtm.R b/R/qtm.R index e98e29ee..c381f24c 100644 --- a/R/qtm.R +++ b/R/qtm.R @@ -154,6 +154,10 @@ qtm <- function(shp, if (!"shape" %in% called) args_f$shape = NULL if (!"col" %in% called) args_f$col = NULL } + if (f == "tm_lines") { + if (!"col" %in% called) args_f$col = NULL + } + if (f == "tm_polygons") { if (length(args_other)) { # v3 confusion: tm_polygons used col while qtm used fill, therefore, tm_polygons will be called will col @@ -162,7 +166,7 @@ qtm <- function(shp, args_f$fill = NULL } } - + args_f$called_from = "qtm" options = opt_tm_sf()[[c(tm_polygons = "polygons", tm_lines = "lines", tm_symbols = "points")[f]]] g = g + do.call(f, c(args_f, args_other, list(options = options))) } diff --git a/R/tm_layers_lines.R b/R/tm_layers_lines.R index bb908b6c..3a5298c1 100644 --- a/R/tm_layers_lines.R +++ b/R/tm_layers_lines.R @@ -92,11 +92,11 @@ tm_lines = function(col = tm_const(), args_called = as.list(match.call()[-1]) #lapply(as.list(match.call()[-1]), eval, envir = parent.frame()) if (any(v3_only("tm_lines") %in% names(args))) { - layer_fun = paste0("tm_", {if ("called_from" %in% names(args)) { + layer_fun = if ("called_from" %in% names(args)) { args$called_from } else { "lines" - }}) + } v3_start_message() if (!("style" %in% names(args))) { @@ -149,11 +149,14 @@ tm_lines = function(col = tm_const(), } else { stop("unknown style") } - if ("style" %in% names(args)) { - v3_tm_scale_instead_of_style(style, scale_fun = col.scale.args$fun_pref, vv = "col", layer_fun = layer_fun, arg_list = v3_list_get()) - } else { - v3_tm_scale(scale_fun = "", vv = "col", layer_fun = layer_fun, arg_list = v3_list_get()) + if (!(args$called_from == "qtm" && (!"col" %in% names(args)))) { + if ("style" %in% names(args)) { + v3_tm_scale_instead_of_style(style, scale_fun = col.scale.args$fun_pref, vv = "col", layer_fun = layer_fun, arg_list = v3_list_get()) + } else { + v3_tm_scale(scale_fun = "", vv = "col", layer_fun = layer_fun, arg_list = v3_list_get()) + } } + col.scale = do.call("tm_scale", args = col.scale.args) diff --git a/R/tm_layers_polygons.R b/R/tm_layers_polygons.R index dfc51e19..fe270ed8 100644 --- a/R/tm_layers_polygons.R +++ b/R/tm_layers_polygons.R @@ -129,11 +129,11 @@ tm_polygons = function(fill = tm_const(), if (any(v3_only("tm_polygons") %in% names(args))) { - layer_fun = paste0("tm_", {if ("called_from" %in% names(args)) { + layer_fun = if ("called_from" %in% names(args)) { args$called_from } else { "polygons" - }}) + } v3_start_message() @@ -196,8 +196,6 @@ tm_polygons = function(fill = tm_const(), v3_tm_scale(scale_fun = "", vv = "fill", layer_fun = layer_fun, arg_list = v3_list_get()) } - - fill.scale = do.call("tm_scale", args = fill.scale.args) if ("convert2density" %in% names(args) && args$convert2density) { @@ -205,7 +203,7 @@ tm_polygons = function(fill = tm_const(), v3_convert2density(layer_fun) } - if ("col" %in% names(args_called) && (args$called_from != "fill")) { + if ("col" %in% names(args_called) && (!args$called_from %in% c("tm_fill", "qtm"))) { fill = col col = tm_const() v3_message_col_fill(layer_fun = layer_fun) @@ -217,7 +215,7 @@ tm_polygons = function(fill = tm_const(), col = args$border.col if (!("col" %in% names(args_called))) v3_message_col_fill(layer_fun = layer_fun) } - if (identical(args$called_from, "borders")) { + if (identical(args$called_from, "tm_borders")) { fill = NA } @@ -332,7 +330,7 @@ tm_fill = function(...) { if (!("col" %in% names(args))) { args$col = NA } - args$called_from = "fill" + args$called_from = "tm_fill" do.call(tm_polygons, args) } @@ -344,6 +342,6 @@ tm_borders = function(col = tm_const(), ...) { if (!("fill" %in% names(args))) { args$fill = NA } - args$called_from = "borders" + args$called_from = "tm_borders" do.call(tm_polygons, c(list(col = col), args)) } diff --git a/R/tm_layers_raster.R b/R/tm_layers_raster.R index 5fc3ca61..f95f1321 100644 --- a/R/tm_layers_raster.R +++ b/R/tm_layers_raster.R @@ -76,11 +76,11 @@ tm_raster = function(col = tm_shape_vars(), if (any(v3_only("tm_raster") %in% names(args))) { - layer_fun = paste0("tm_", {if ("called_from" %in% names(args)) { + layer_fun = if ("called_from" %in% names(args)) { args$called_from } else { - "raster" - }}) + "tm_raster" + } v3_start_message() if (!("style" %in% names(args))) { diff --git a/R/tm_layers_symbols.R b/R/tm_layers_symbols.R index 534fb3b9..64682ca1 100644 --- a/R/tm_layers_symbols.R +++ b/R/tm_layers_symbols.R @@ -270,11 +270,11 @@ tm_symbols = function(size = tm_const(), v3_symbols = function(args, args_called) { if (any(v3_only("tm_symbols") %in% names(args))) { - layer_fun = paste0("tm_", {if ("called_from" %in% names(args)) { + layer_fun = if ("called_from" %in% names(args)) { args$called_from } else { "symbols" - }}) + } v3_start_message() if (!("style" %in% names(args))) { @@ -328,6 +328,7 @@ v3_symbols = function(args, args_called) { } else { stop("unknown style") } + if ("style" %in% names(args)) { v3_tm_scale_instead_of_style(style, scale_fun = fill.scale.args$fun_pref, vv = "fill", layer_fun = layer_fun, arg_list = v3_list_get()) } else { @@ -536,7 +537,7 @@ tm_dots = function(fill = tm_const(), ...) { args = c(as.list(environment()), list(...)) - args$called_from = "dots" + args$called_from = "tm_dots" tm = do.call(tm_symbols, args) tm[[1]]$layer = c("dots", "symbols") @@ -585,7 +586,7 @@ tm_bubbles = function(size = tm_const(), ...) { args = c(as.list(environment()), list(...)) - args$called_from = "bubbles" + args$called_from = "tm_bubbles" tm = do.call(tm_symbols, args) tm[[1]]$layer = c("bubbles", "symbols") @@ -632,7 +633,7 @@ tm_squares = function(size = tm_const(), ...) { args = c(as.list(environment()), list(...)) - args$called_from = "squares" + args$called_from = "tm_squares" tm = do.call(tm_symbols, args) tm[[1]]$layer = c("squares", "symbols") tm