Skip to content

Commit

Permalink
improvements in typos, docs / error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed Nov 12, 2024
1 parent 1a47d84 commit 6e55cd0
Show file tree
Hide file tree
Showing 24 changed files with 162 additions and 126 deletions.
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

* New family of functions `tm_chart_*()` to do charting (See `?tm_chart`) (#581)

* New [vignettes](https://r-tmap.github.io/tmap/articles/) available to explain how to upgrade your code to tmap v4

# tmap 3.3-4
- (!) last version of tmap 3.x. Next CRAN version will be tmap 4.x (release planned at the end of 2023)
- (!) last version of tmap 3.x. Next CRAN version will be tmap 4.x
- fixed bug (some stars appeared upside down in plot mode)
- fixed newly introduced shiny bug (#767)

Expand Down Expand Up @@ -48,7 +50,7 @@
- interactive maps in origin CRS working: `tmap_options(projection = 0, basemaps = NULL)`
- added `tm_mouse_coordinates()` to show mouse coordinates in view mode
- added `tmap_design_mode()` to toggle the design mode.
- made backgrond symbol grob shapes transparent
- made background symbol grob shapes transparent
- added in.iframe and `selfcontained` to `tmap_save()`
- improved `tm_add_legend()`: added `type = "title"` for title only legend elements
- added `ttmp()` which shows the last map in the other mode.
Expand Down
29 changes: 20 additions & 9 deletions R/messages.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,25 @@ message_reg = function(id) {

message_comp_scale = function() {
if (!message_thrown("comp_scale")) {
cli::cli_inform("{.field [plot mode]} fit legend/component: Some legend items or map compoments do not fit well, and are therefore rescaled. Set the tmap option 'component.autoscale' to FALSE to disable rescaling.",
.frequency_id = "comp_scale")
cli::cli_inform(c(
"{.field [plot mode]} fit legend/component: Some legend items or map compoments do not fit well, and are therefore rescaled.",
i = "Set the tmap option {.code component.autoscale = FALSE} to disable rescaling."
),
.frequency_id = "comp_scale"
)
message_reg("comp_scale")
}
NULL
}

message_comp_high_wide = function(stack) {
if (!message_thrown("comp_scale")) {
cli::cli_inform("{.field [plot mode]} legend/component: Some components or legends are too {.val ifelse(stack == 'vertical', 'high', 'wide')} and are therefore rescaled. Set the tmap option {.code component.autoscale} to {.code FALSE} to disable rescaling.",
.frequency_id = "comp_scale")
cli::cli_inform(c(
"{.field [plot mode]} legend/component: Some components or legends are too {.val {ifelse(stack == 'vertical', 'high', 'wide')}} and are therefore rescaled.",
"i" = "Set the tmap option {.code component.autoscale = FALSE} to disable rescaling."
),
.frequency_id = "comp_scale"
)
message_reg("comp_scale")
}
NULL
Expand Down Expand Up @@ -54,7 +62,7 @@ message_c4a = function(old_palette_name, info, fullname = FALSE) {

message_nothing_to_show = function(any_groups) {
if (any_groups) {
cli::cli_inform("{.field [nothing to show]} no data layers defined after {.code tm_shape}",
cli::cli_inform("{.field [nothing to show]} no data layers defined after {.fn tm_shape}",
.frequency_id = "nothing")
} else {
cli::cli_inform("{.field [nothing to show]} no data layers defined",
Expand All @@ -65,9 +73,9 @@ message_nothing_to_show = function(any_groups) {

message_wrapstack = function(horizontal = TRUE) {
if (horizontal) {
cli::cli_inform("{.field [facets]} use {.code tm_facets_hstack()} instead of {.code tm_facets_wrap()} to put the legends next to and aligned with the facets")
cli::cli_inform("{.field [facets]} use {.fn tm_facets_hstack} instead of {.fn tm_facets_wrap} to put the legends next to and aligned with the facets.")
} else {
cli::cli_inform("{.field [facets]} use {.code tm_facets_vstack()} instead of {.code tm_facets_wrap()} to put the legends next to and aligned with the facets")
cli::cli_inform("{.field [facets]} use {.fn tm_facets_vstack} instead of {.fn tm_facets_wrap} to put the legends next to and aligned with the facets.")
}
NULL
}
Expand All @@ -76,13 +84,16 @@ message_pos_auto = function(type) {
if (!message_thrown("pos_auto")) {
fun = if (type == "autoout") "tm_pos_auto_out()" else "tm_pos_auto_in()"
fun2 = if (type == "autoout") "tm_pos_out()" else "tm_pos_in()"
cli::cli_inform("{.field [position]} use {.val fun2} instead of {.val fun}. The latter should be used with {.code tmap_options()}.")
cli::cli_inform("{.field [position]} use {.val {fun2}} instead of {.val {fun}}. The latter should be used with {.fn tmap_options}.")
message_reg("pos_auto")
}
NULL
}

error_dimvalues = function() {
stop("tm_vars(): \"dimvalues\" has been used, but the shape object does not contain any dimensions; please use \"x\" to specify variables", call. = FALSE)
cli::cli_abort(
"{.val dimvalues} has been used, but the shape object does not contain any dimensions; please use {.arg x} to specify variables",
call = call("tm_vars")
)
}

2 changes: 1 addition & 1 deletion R/messages_v4_v3.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ v3_list_get = function() {
v3_impute = function(args, name, value, new_name = name) {
if (name %in% names(args)) {
res = args[[name]]
if (is.list(res) && length(grep("format", name, fixed =TRUE)) == 0 && !is.list(res[[1]])) {
if (is.list(res) && !grepl("format", name, fixed = TRUE) && !is.list(res[[1]])) {
res = res[[1]]
mult = TRUE
} else if (new_name %in% c("title", "na.show", "orientation", "reverse", "interval.closure", "drop.levels", "midpoint", "as.count", "values.repeat", "values.scale", "value.na", "value.null", "value.neutral", "label.na", "label.null")) {
Expand Down
2 changes: 1 addition & 1 deletion R/misc_other.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ get_asp_ratio = function (x, width = 700, height = 700, res = 100) {
# get aspect ratios of a list of bounding boxes
get_asp = function(bbxl) {
vapply(bbxl, function(bbxi) {
if (is.na(bbxi)) as.numeric(NA) else get_asp_ratio(bbxi)
if (is.na(bbxi)) NA_real_ else get_asp_ratio(bbxi)
}, FUN.VALUE = numeric(1))
}

Expand Down
4 changes: 2 additions & 2 deletions R/process_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,12 @@ process_meta = function(o, d, cdt, aux) {

legend.position = NA

if (!is.logical(set.bounds)) if (!length(set.bounds)==4 || !is.numeric(set.bounds)) stop("Incorrect set_bounds argument", call.=FALSE)
if (!is.logical(set.bounds)) if (length(set.bounds) !=4 || !is.numeric(set.bounds)) stop("Incorrect set_bounds argument", call.=FALSE)


if (!is.na(set.view[1])) {
if (!is.numeric(set.view)) stop("set.view is not numeric")
if (!length(set.view) %in% c(1,3)) stop("set.view does not have length 1 or 3")
if (!length(set.view) %in% c(1, 3)) stop("set.view does not have length 1 or 3")
}
if (!is.na(set.zoom.limits[1])) {
if (!is.numeric(set.zoom.limits)) stop("set.zoom.limits is not numeric")
Expand Down
4 changes: 1 addition & 3 deletions R/shapeTM.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ stm_bbox = function(shpTM, tmapID, crs) {
shp = shpTM$shp
shpID = shpTM$tmapID

if (length(tmapID) ==0 ) return(sf::st_bbox(as.numeric(NA)))
if (length(tmapID) == 0) return(sf::st_bbox(NA_real_))
# filter the shape?
do_filter = (length(tmapID) != length(shpID)) || (!all(tmapID == shpID))

Expand Down Expand Up @@ -119,5 +119,3 @@ bb_ll_valid = function(bbx) {
bbx[4] = min(bbx[4], 90)
bbx
}


4 changes: 3 additions & 1 deletion R/step1_helper_facets.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ step1_rearrange_facets = function(tmo, o) {
vars = shpvars[value$x]
}
} else if (!is.na(value$n)) {
if (length(shpvars) < value$n) stop("tm_vars defined for n = ", value$n, " while there are only ", length(shpvars), " variables", call. = FALSE)
if (length(shpvars) < value$n) {
stop("tm_vars defined for n = ", value$n, " while there are only ", length(shpvars), " variables", call. = FALSE)
}
vars = shpvars[1L:value$n]
} else {
vars = shpvars
Expand Down
20 changes: 10 additions & 10 deletions R/step4_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ process_components = function(cdt, o) {
cdt$cell.v = sapply(cdt$comp, function(l) {x = l$position$cell.v; if (is.null(x)) NA else x})
cdt$pos.h = sapply(cdt$comp, function(l) {x = l$position$pos.h; if (is.null(x)) NA else x})
cdt$pos.v = sapply(cdt$comp, function(l) {x = l$position$pos.v; if (is.null(x)) NA else x})
cdt$z = sapply(cdt$comp, function(l) {x = l$z; if (is.null(x)) as.integer(NA) else x})
cdt$z = sapply(cdt$comp, function(l) {x = l$z; if (is.null(x)) NA_integer_ else x})

# to make sure legends positions are based on one-facet-per-page
if (o$type == "page") {
Expand Down Expand Up @@ -115,7 +115,7 @@ process_components = function(cdt, o) {
#
# }

#cdt[, page := as.integer(NA)]
#cdt[, page := NA_integer_]


cdt
Expand Down Expand Up @@ -261,9 +261,9 @@ step4_plot = function(tm, vp, return.asp, show, in.shiny, knit, args) {

cdt_cmp = if (length(cmp) && !o$legend.only) {
data.table::rbindlist(lapply(cmp, function(cp) {
data.table::data.table(by1__ = as.integer(NA),
by2__ = as.integer(NA),
by3__ = as.integer(NA),
data.table::data.table(by1__ = NA_integer_,
by2__ = NA_integer_,
by3__ = NA_integer_,
comp = list(cp))
}))
} else {
Expand Down Expand Up @@ -474,17 +474,17 @@ step4_plot = function(tm, vp, return.asp, show, in.shiny, knit, args) {
if (o$panel.type != "none") {
cdt = rbindlist(c(list(cdt), mapply(function(lab, i) {
data.table::data.table(by1__ = i,
by2__ = as.integer(NA),
by3__ = as.integer(NA),
by2__ = NA_integer_,
by3__ = NA_integer_,
comp = list(impute_comp(tm_title(lab)[[1]], o)),
class= "in",
cell.h = NA,
cell.v = NA,
pos.h = "left",
pos.v = "top",
z = 1,
facet_row = as.character(NA),
facet_col = as.character(NA),
facet_row = NA_character_,
facet_col = NA_character_,
stack_auto = TRUE,
stack = "vertical",
legW = 0,
Expand Down Expand Up @@ -765,7 +765,7 @@ step4_plot = function(tm, vp, return.asp, show, in.shiny, knit, args) {
}

legs_out = copy(cdt[!is_in])
legs_out[, page:=as.integer(NA)]
legs_out[, page:=NA_integer_]

# legs_out[, bbox:=list()]
# legs_out[, units:=list()]
Expand Down
4 changes: 2 additions & 2 deletions R/tm_add_legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ tm_add_legend = function(...,
group = NA,
group.control = "check",
resize.as.group = FALSE,
z = as.integer(NA)) {
if (missing(labels)) stop("tm_add_legend: labels required", call. = FALSE)
z = NA_integer_) {
rlang::check_required(labels)

args = lapply(as.list(rlang::call_match(defaults = TRUE)[-1]), eval, envir = parent.frame())

Expand Down
68 changes: 34 additions & 34 deletions R/tm_chart.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tm_chart_histogram = function(breaks,

args = lapply(as.list(rlang::call_match()[-1]), eval, envir = parent.frame())

if (!("z" %in% (names(args)))) args$z = as.integer(NA)
if (!("z" %in% (names(args)))) args$z = NA_integer_
args$show = TRUE
args$type = "histogram"
args$summary = "binned"
Expand All @@ -40,19 +40,19 @@ tm_chart_histogram = function(breaks,

#' @rdname tm_chart
#' @export
tm_chart_bar = function( plot.axis.x,
plot.axis.y,
extra.ggplot2,
position,
width,
height,
stack,
z,
group.frame,
resize.as.group) {
tm_chart_bar = function(plot.axis.x,
plot.axis.y,
extra.ggplot2,
position,
width,
height,
stack,
z,
group.frame,
resize.as.group) {
args = lapply(as.list(rlang::call_match()[-1]), eval, envir = parent.frame())

if (!("z" %in% (names(args)))) args$z = as.integer(NA)
if (!("z" %in% (names(args)))) args$z = NA_integer_
args$show = TRUE
args$type = "bar"
args$summary = "binned"
Expand All @@ -63,15 +63,15 @@ tm_chart_bar = function( plot.axis.x,
#' @rdname tm_chart
#' @export
tm_chart_donut = function(position,
width,
height,
stack,
z,
group.frame,
resize.as.group) {
width,
height,
stack,
z,
group.frame,
resize.as.group) {
args = lapply(as.list(rlang::call_match()[-1]), eval, envir = parent.frame())

if (!("z" %in% (names(args)))) args$z = as.integer(NA)
if (!("z" %in% (names(args)))) args$z = NA_integer_
args$show = TRUE
args$type = "donut"
args$summary = "binned"
Expand All @@ -89,7 +89,7 @@ tm_chart_violin = function(position,
resize.as.group) {
args = lapply(as.list(rlang::call_match()[-1]), eval, envir = parent.frame())

if (!("z" %in% (names(args)))) args$z = as.integer(NA)
if (!("z" %in% (names(args)))) args$z = NA_integer_
args$show = TRUE
args$type = "violin"
args$summary = "raw_nna"
Expand All @@ -99,15 +99,15 @@ tm_chart_violin = function(position,
#' @rdname tm_chart
#' @export
tm_chart_box = function(position,
width,
height,
stack,
z,
group.frame,
resize.as.group) {
width,
height,
stack,
z,
group.frame,
resize.as.group) {
args = lapply(as.list(rlang::call_match()[-1]), eval, envir = parent.frame())

if (!("z" %in% (names(args)))) args$z = as.integer(NA)
if (!("z" %in% (names(args)))) args$z = NA_integer_
args$show = TRUE
args$type = "box"
args$summary = "raw_nna"
Expand All @@ -125,15 +125,15 @@ tm_chart_none = function() {
#' @rdname tm_chart
#' @export
tm_chart_heatmap = function(position,
width,
height,
stack,
z,
group.frame,
resize.as.group) {
width,
height,
stack,
z,
group.frame,
resize.as.group) {
args = lapply(as.list(rlang::call_match()[-1]), eval, envir = parent.frame())

if (!("z" %in% (names(args)))) args$z = as.integer(NA)
if (!("z" %in% (names(args)))) args$z = NA_integer_
args$show = TRUE
args$type = "heatmap"
args$summary = "binned2D"
Expand Down
Loading

0 comments on commit 6e55cd0

Please sign in to comment.