Skip to content

Commit

Permalink
convert another message to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed Aug 22, 2024
1 parent 14b8f12 commit d961394
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 26 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ ubuntu_17_installation.sh
^data-raw$
^.covrignore$
^vignettes/tmap-getstarted.Rmd$
^tests/testthat/Rplots.pdf$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ docs
/doc/
/Meta/
inst/doc

tests/testthat/Rplots.pdf
61 changes: 35 additions & 26 deletions R/messages_v4_v3.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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)
Expand All @@ -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"
Expand All @@ -91,10 +91,10 @@ v3_tm_scale = function(scale_fun, vv, layer_fun, arg_list) {
} else {
NULL

Check warning on line 92 in R/messages_v4_v3.R

View check run for this annotation

Codecov / codecov/patch

R/messages_v4_v3.R#L92

Added line #L92 was not covered by tests
}

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}(<HERE>).",
"{.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}(<HERE>).",
"i" = x
))
}
Expand All @@ -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)
Expand All @@ -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))
Expand All @@ -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(

Check warning on line 143 in R/messages_v4_v3.R

View check run for this annotation

Codecov / codecov/patch

R/messages_v4_v3.R#L142-L143

Added lines #L142 - L143 were not covered by tests

))

Check warning on line 145 in R/messages_v4_v3.R

View check run for this annotation

Codecov / codecov/patch

R/messages_v4_v3.R#L145

Added line #L145 was not covered by tests
message(paste0("[v3->v4] ", fun, "(): use '", new, " = ", value_new, "' instead of '", old, " = ", value_old, "'"))
list(args = args, called = called)
} else {
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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"
)

Check warning on line 214 in R/messages_v4_v3.R

View check run for this annotation

Codecov / codecov/patch

R/messages_v4_v3.R#L209-L214

Added lines #L209 - L214 were not covered by tests
}
NULL
}

v3_tm_facets_free_scales = function() {
message(paste0("[v3->v4] tm_facets(): migrate each 'free.scales.<X>' argument to the argument '<X>.free' of the corresponding layer function"))
cli::cli_inform(c(
"{.field [v3->v4]} {.fn tm_facets}: migrate each 'free.scales.<X>' argument to the argument '<X>.free' of the corresponding layer function."
),
.frequency_id = "facets",
.frequency = "always"
)

Check warning on line 225 in R/messages_v4_v3.R

View check run for this annotation

Codecov / codecov/patch

R/messages_v4_v3.R#L220-L225

Added lines #L220 - L225 were not covered by tests
}


Expand All @@ -235,28 +243,28 @@ 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) {
message(paste0("[v3->v4] ", layer_fun, "(): use 'fill' for the fill color of polygons/symbols (instead of 'col'), and 'col' for the outlines (instead of 'border.col')"))
}

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."))

Check warning on line 254 in R/messages_v4_v3.R

View check run for this annotation

Codecov / codecov/patch

R/messages_v4_v3.R#L254

Added line #L254 was not covered by tests
}


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)

Check warning on line 263 in R/messages_v4_v3.R

View check run for this annotation

Codecov / codecov/patch

R/messages_v4_v3.R#L263

Added line #L263 was not covered by tests
}

v3_add_legend = function(type, args) {
newtype = c(fill = "polygons", symbol = "symbols", line = "lines")
newtype = c(fill = "polygons", symbol = "symbols", line = "lines")

Check warning on line 267 in R/messages_v4_v3.R

View check run for this annotation

Codecov / codecov/patch

R/messages_v4_v3.R#L267

Added line #L267 was not covered by tests
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]))
Expand All @@ -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)")
}

Expand All @@ -282,5 +291,5 @@ v3_tm_rgb = function(r, g, b) {
# message("[v3->v4] ", layer_fun, "(): use '", vv, ".scale = list(<scale1>, <scale2>, ...)' to specify small multiples")
# message_reg("multiple_args")
# }
#
# }
#
# }

0 comments on commit d961394

Please sign in to comment.