From d96139431c8fb0d3f4f8816152ac4983abe00cc7 Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 22 Aug 2024 09:23:12 -0400 Subject: [PATCH] convert another message to cli --- .Rbuildignore | 1 + .gitignore | 2 ++ R/messages_v4_v3.R | 61 ++++++++++++++++++++++++++-------------------- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index af9e1444..ae0fc58b 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -25,3 +25,4 @@ ubuntu_17_installation.sh ^data-raw$ ^.covrignore$ ^vignettes/tmap-getstarted.Rmd$ +^tests/testthat/Rplots.pdf$ diff --git a/.gitignore b/.gitignore index 2732aca5..23a9cf53 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,5 @@ docs /doc/ /Meta/ inst/doc + +tests/testthat/Rplots.pdf \ No newline at end of file diff --git a/R/messages_v4_v3.R b/R/messages_v4_v3.R index cbcf5ae9..3fe8812c 100644 --- a/R/messages_v4_v3.R +++ b/R/messages_v4_v3.R @@ -29,7 +29,7 @@ v3_title = function(fun) { v3_main_title = function(fun) { id = paste0(fun, "main.title") - + cli::cli_inform("{.field [v3->v4]} {.fn {fun}}: use 'tm_title()' instead of the {.code {fun}(main.title = )}", .frequency_id = id, .frequency = "always") } @@ -65,10 +65,10 @@ v3_tm_scale_instead_of_style = function(style, scale_fun, vv, layer_fun, arg_lis xtra = NULL x = NULL } - + cli::cli_inform(c( "{.field [v3->v4]} {.fn {layer_fun}}: instead of {.code style = {.str {style}}}, use {vv}.scale = {.fn tm_scale_{scale_fun}}.", - i = xtra, + i = xtra, x )) message_reg(m) @@ -78,7 +78,7 @@ v3_tm_scale_instead_of_style = function(style, scale_fun, vv, layer_fun, arg_lis v3_tm_scale = function(scale_fun, vv, layer_fun, arg_list) { m = paste0("scale_", scale_fun, "_vv_", vv) - + if (!message_thrown(m)) { scale_fun = if (scale_fun == "") { "tm_scale" @@ -91,10 +91,10 @@ v3_tm_scale = function(scale_fun, vv, layer_fun, arg_list) { } else { NULL } - + al = v3_list_text(olds = arg_list$old, news = arg_list$new) cli::cli_inform(c( - "{.field [v3->v4]} {.fn {layer_fun}}: migrate the argument(s) related to the scale of the visual variable {.var {vv}} namely {al} to {vv}.scale = {scale_fun}().", + "{.field [v3->v4]} {.fn {layer_fun}}: migrate the argument(s) related to the scale of the visual variable {.var {vv}} namely {al} to {vv}.scale = {scale_fun}().", "i" = x )) } @@ -103,10 +103,6 @@ v3_tm_scale = function(scale_fun, vv, layer_fun, arg_list) { NULL } - - - - v3_instead_message = function(arg_old, arg_new, fun) { v3_start_message() id <- paste0(fun, arg_old, arg_new) @@ -118,15 +114,14 @@ v3_instead_message = function(arg_old, arg_new, fun) { ) } - v3_instead = function(args_called, old, new, fun, extra_called = character()) { args = args_called$args called = args_called$called - + if (old %in% called) { args[[new]] = args[[old]] args[[old]] = NULL - + # may be needed to trigger something (e.g. "shape" to use symbols instead of dots) if (length(extra_called)) { called = unique(c(called, extra_called)) @@ -139,12 +134,15 @@ v3_instead = function(args_called, old, new, fun, extra_called = character()) { v3_instead_value = function(args_called, old, new, fun, value_old, value_new) { args = args_called$args called = args_called$called - + if (old %in% called) { if (identical(args[[old]], value_old)) { args[[old]] = NULL args[[new]] = value_new - if (is.null(value_old)) value_old = "NULL" + if (is.null(value_old)) value_old = "NULL" + cli::cli_inform(c( + + )) message(paste0("[v3->v4] ", fun, "(): use '", new, " = ", value_new, "' instead of '", old, " = ", value_old, "'")) list(args = args, called = called) } else { @@ -157,7 +155,7 @@ v3_instead_value = function(args_called, old, new, fun, value_old, value_new) { v3_list_init = function() { .TMAP$v3_list = list(old = character(), new = character(), mult = FALSE) - invisible(NULL) + invisible(NULL) } v3_list_impute_item = function(name, new_name, mult = FALSE) { .TMAP$v3_list$old = c(.TMAP$v3_list$old, name) @@ -194,7 +192,7 @@ v3_list_text = function(olds, news) { } else { paste0("'", x, "' (use '", y, "')") } - }, olds , news, SIMPLIFY = FALSE), sep = ", ")) + }, olds , news, SIMPLIFY = FALSE), sep = ", ")) } v3_tm_legend = function(fun, vv, arg_list) { @@ -208,13 +206,23 @@ v3_tm_legend = function(fun, vv, arg_list) { v3_tm_facets = function(arg_list) { if (length(arg_list$old)) { al = v3_list_text(olds = arg_list$old, news = arg_list$new) - message(paste0("[v3->v4] tm_facets(): rename the following argument(s): ", al)) + cli::cli_inform(c( + "{.field [v3->v4]} {.fn tm_facets}: rename the following argument(s): {al}." + ), + .frequency_id = "facets2", + .frequency = "always" + ) } NULL } v3_tm_facets_free_scales = function() { - message(paste0("[v3->v4] tm_facets(): migrate each 'free.scales.' argument to the argument '.free' of the corresponding layer function")) + cli::cli_inform(c( + "{.field [v3->v4]} {.fn tm_facets}: migrate each 'free.scales.' argument to the argument '.free' of the corresponding layer function." + ), + .frequency_id = "facets", + .frequency = "always" + ) } @@ -235,7 +243,7 @@ v3_tm_legend_general = function(fun) { v3_tm_chart_hist = function(layer_fun, vv, arg) { message(paste0("[v3->v4] ", layer_fun, "(): use '", vv, ".chart = tm_chart_histogram()' instead of '", arg, " = TRUE'")) - + } v3_message_col_fill = function(layer_fun = layer_fun) { @@ -243,20 +251,20 @@ v3_message_col_fill = function(layer_fun = layer_fun) { } v3_message_vv_null = function(layer_fun = layer_fun) { - message(paste0("[v3->v4] ", layer_fun, "(): use 'NA' instead of 'NULL' to hide a visual variable")) + message(paste0("[v3->v4] ", layer_fun, "(): use 'NA' instead of 'NULL' to hide a visual variable.")) } v3_message_fill_alpha = function(layer_fun = layer_fun) { - message(paste0("[v3->v4] ", layer_fun, "(): use 'fill_alpha' instead of 'alpha'")) + v3_instead_message("alpha", "fill_alpha", layer_fun) } v3_message_col_alpha = function(layer_fun = layer_fun, orig = "border.alpha") { - message(paste0("[v3->v4] ", layer_fun, "(): use 'col_alpha' instead of '", orig, "'")) + v3_instead_message(orig, arg_new = "col_alpha", layer_fun) } v3_add_legend = function(type, args) { - newtype = c(fill = "polygons", symbol = "symbols", line = "lines") + newtype = c(fill = "polygons", symbol = "symbols", line = "lines") message(paste0("[v3->v4] tm_add_legend(): use 'type = \"", newtype[type],"\"' instead of 'type = \"", type,"\"'")) if ("col" %in% args && !c("fill" %in% args)) { message(paste0("[v3->v4] tm_add_legend(): use 'fill' instead of 'coll' for the fill color of ", newtype[type])) @@ -273,6 +281,7 @@ v3_opt = function(olds, news, layer_fun) { v3_tm_rgb = function(r, g, b) { + message("[v3->v4] ", "tm_rgb", "(): instead of using r = ", r, ", g = ", g, ", and b = ", b, ", please use col = tm_vars(c(", r, ", ", g, ", ", b, "), multivariate = TRUE)") } @@ -282,5 +291,5 @@ v3_tm_rgb = function(r, g, b) { # message("[v3->v4] ", layer_fun, "(): use '", vv, ".scale = list(, , ...)' to specify small multiples") # message_reg("multiple_args") # } -# -# } \ No newline at end of file +# +# }