Skip to content
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

improvements in typos, docs / error messages #963

Merged
merged 1 commit into from
Nov 13, 2024
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
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
3 changes: 2 additions & 1 deletion R/global-variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ utils::globalVariables(c(
"scale.factor", "set.bounds",
"split_geometry_collection", "stack_auto", "t1",
"t2", "t3", "t4", "text.fontface", "text.fontfamily", "title.bg.alpha",
"tmapID__", "vneutral"
"tmapID__", "vneutral",
"panel.show", "set_to_stack_message", "rev1", "rev2", "rev3", "facet.flip", "panel.show"
))

# Add more to silence R CMD CHECK (see if some are false positive)
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_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"
)

Check warning on line 22 in R/messages.R

View check run for this annotation

Codecov / codecov/patch

R/messages.R#L17-L22

Added lines #L17 - L22 were not covered by tests
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"
)

Check warning on line 35 in R/messages.R

View check run for this annotation

Codecov / codecov/patch

R/messages.R#L30-L35

Added lines #L30 - L35 were not covered by tests
message_reg("comp_scale")
}
NULL
Expand Down Expand Up @@ -54,7 +62,7 @@

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}",

Check warning on line 65 in R/messages.R

View check run for this annotation

Codecov / codecov/patch

R/messages.R#L65

Added line #L65 was not covered by tests
.frequency_id = "nothing")
} else {
cli::cli_inform("{.field [nothing to show]} no data layers defined",
Expand All @@ -65,9 +73,9 @@

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

Check warning on line 76 in R/messages.R

View check run for this annotation

Codecov / codecov/patch

R/messages.R#L76

Added line #L76 was not covered by tests
} 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.")

Check warning on line 78 in R/messages.R

View check run for this annotation

Codecov / codecov/patch

R/messages.R#L78

Added line #L78 was not covered by tests
}
NULL
}
Expand All @@ -76,13 +84,16 @@
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}.")

Check warning on line 87 in R/messages.R

View check run for this annotation

Codecov / codecov/patch

R/messages.R#L87

Added line #L87 was not covered by tests
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")
)

Check warning on line 97 in R/messages.R

View check run for this annotation

Codecov / codecov/patch

R/messages.R#L94-L97

Added lines #L94 - L97 were not covered by tests
}

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) && !any(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 @@

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

Check warning on line 586 in R/process_meta.R

View check run for this annotation

Codecov / codecov/patch

R/process_meta.R#L586

Added line #L586 was not covered by tests
}
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 @@
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)
}

Check warning on line 160 in R/step1_helper_facets.R

View check run for this annotation

Codecov / codecov/patch

R/step1_helper_facets.R#L158-L160

Added lines #L158 - L160 were not covered by tests
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 @@
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 @@
#
# }

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


cdt
Expand Down Expand Up @@ -261,9 +261,9 @@

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_,

Check warning on line 266 in R/step4_plot.R

View check run for this annotation

Codecov / codecov/patch

R/step4_plot.R#L264-L266

Added lines #L264 - L266 were not covered by tests
comp = list(cp))
}))
} else {
Expand Down Expand Up @@ -474,17 +474,17 @@
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_,

Check warning on line 478 in R/step4_plot.R

View check run for this annotation

Codecov / codecov/patch

R/step4_plot.R#L477-L478

Added lines #L477 - L478 were not covered by tests
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_,

Check warning on line 487 in R/step4_plot.R

View check run for this annotation

Codecov / codecov/patch

R/step4_plot.R#L486-L487

Added lines #L486 - L487 were not covered by tests
stack_auto = TRUE,
stack = "vertical",
legW = 0,
Expand Down Expand Up @@ -765,7 +765,7 @@
}

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 @@

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_

Check warning on line 34 in R/tm_chart.R

View check run for this annotation

Codecov / codecov/patch

R/tm_chart.R#L34

Added line #L34 was not covered by tests
args$show = TRUE
args$type = "histogram"
args$summary = "binned"
Expand All @@ -40,19 +40,19 @@

#' @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_

Check warning on line 55 in R/tm_chart.R

View check run for this annotation

Codecov / codecov/patch

R/tm_chart.R#L55

Added line #L55 was not covered by tests
args$show = TRUE
args$type = "bar"
args$summary = "binned"
Expand All @@ -63,15 +63,15 @@
#' @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_

Check warning on line 74 in R/tm_chart.R

View check run for this annotation

Codecov / codecov/patch

R/tm_chart.R#L74

Added line #L74 was not covered by tests
args$show = TRUE
args$type = "donut"
args$summary = "binned"
Expand All @@ -89,7 +89,7 @@
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_

Check warning on line 92 in R/tm_chart.R

View check run for this annotation

Codecov / codecov/patch

R/tm_chart.R#L92

Added line #L92 was not covered by tests
args$show = TRUE
args$type = "violin"
args$summary = "raw_nna"
Expand All @@ -99,15 +99,15 @@
#' @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_

Check warning on line 110 in R/tm_chart.R

View check run for this annotation

Codecov / codecov/patch

R/tm_chart.R#L110

Added line #L110 was not covered by tests
args$show = TRUE
args$type = "box"
args$summary = "raw_nna"
Expand All @@ -125,15 +125,15 @@
#' @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_

Check warning on line 136 in R/tm_chart.R

View check run for this annotation

Codecov / codecov/patch

R/tm_chart.R#L136

Added line #L136 was not covered by tests
args$show = TRUE
args$type = "heatmap"
args$summary = "binned2D"
Expand Down
Loading