Skip to content

Commit

Permalink
Cmd check fix (#5)
Browse files Browse the repository at this point in the history
* Update example of tm_layout to silence R CMD CHECK note.

* Update tm_symbols example to silence R CMD CHECK NOTE

* Fix R CMD CHECK on class

* Add :: for non-base functions.

* Remove :: or ::: usage for internal tmap functions.
  • Loading branch information
olivroy authored Sep 14, 2023
1 parent 9a5ba87 commit 5df6369
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 48 deletions.
2 changes: 1 addition & 1 deletion R/misc_stars.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ regular_intervals = function (x, epsilon = 1e-10) {
}
}

get_downsample = function(dims, px = round(dev.size("px") * (par("fin")[1] / dev.size()[1]))) {
get_downsample = function(dims, px = round(dev.size("px") * (graphics::par("fin")[1] / dev.size()[1]))) {
floor(sqrt(prod(dims) / prod(px)))
}

Expand Down
4 changes: 2 additions & 2 deletions R/process_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ prepreprocess_meta = function(o, vp) {
within(o, {
vp = vp
if (is.null(vp)) {
devsize = par("fin") #dev.size() MAY NOT BE EQUAL IN RSTUDIO: https://github.com/rstudio/rstudio/issues/10723
devsize = graphics::par("fin") #dev.size() MAY NOT BE EQUAL IN RSTUDIO: https://github.com/rstudio/rstudio/issues/10723
} else {
if (is.character(vp)) seekViewport(vp) else pushViewport(vp)
devsize = c(grid::convertWidth(grid::unit(1, "npc"), unitTo = "inch", valueOnly = TRUE),
Expand All @@ -23,7 +23,7 @@ prepreprocess_meta = function(o, vp) {
}


lin = par("cin")[2]# * scale
lin = graphics::par("cin")[2]# * scale

lineH = lin / devsize[2] * scale
lineW = lin / devsize[1] * scale
Expand Down
2 changes: 1 addition & 1 deletion R/tmapGridAux.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ tmapGridGridPrep = function(a, bs, id, o) {
bbx_orig <- bbx
bbx <- suppressWarnings(bb(bbx, current.projection = crs_bb, projection = crs))
}
sasp = tmap:::get_asp_ratio(bbx)
sasp = get_asp_ratio(bbx)

## automatically determine number of grid lines
if (is.na(n.x) && !is.na(n.y)) {
Expand Down
4 changes: 2 additions & 2 deletions R/tmapGridComp_leg_landscape.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ tmapGridLegPlot.tm_legend_standard_landscape = function(comp, o, fH, fW) {

if (vary_fill) {
cols = unlist(fill_list)[id1:(10*(nlev2-1) + id2)]
cols_alph = paste0(cols, tmap::num_to_hex(gp$fill_alpha[1] * 255))
cols_alph = paste0(cols, num_to_hex(gp$fill_alpha[1] * 255))
} else {
alph = unlist(alpha_list)[id1:(10*(nlev2-1) + id2)]
cols_alph = paste0(col2hex(gp$fill[1]), tmap::num_to_hex(alph * 255))
cols_alph = paste0(col2hex(gp$fill[1]), num_to_hex(alph * 255))
}
grItems1 = list(gridCell(6, comp$item_ids[lvs], grid::rectGrob(x = x1 + 0.5*w, width= w, gp=gpar(fill = grid::linearGradient(colours = cols_alph), col = NA))))
} else {
Expand Down
4 changes: 2 additions & 2 deletions R/tmapGridComp_leg_portrait.R
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,10 @@ tmapGridLegPlot.tm_legend_standard_portrait = function(comp, o, fH, fW) {

if (vary_fill) {
cols = unlist(fill_list)[id1:(10*(nlev2-1) + id2)]
cols_alph = paste0(cols, tmap::num_to_hex(gp$fill_alpha[1] * 255))
cols_alph = paste0(cols, num_to_hex(gp$fill_alpha[1] * 255))
} else {
alph = unlist(alpha_list)[id1:(10*(nlev2-1) + id2)]
cols_alph = paste0(col2hex(gp$fill[1]), tmap::num_to_hex(alph * 255))
cols_alph = paste0(col2hex(gp$fill[1]), num_to_hex(alph * 255))
}
grItems1 = list(gridCell(comp$item_ids[lvs], 3, grid::rectGrob(y = y2 + 0.5*h, height= h, gp=gpar(fill = grid::linearGradient(colours = rev(cols_alph)), col = NA))))
} else {
Expand Down
2 changes: 1 addition & 1 deletion R/tmapLeafletInit.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ tmapLeafletAux = function(o, q) {
lapply(lfp, function(lf) {
if (length(pids)) for (pid in pids) lf = leaflet::addMapPane(lf, q$pane[pid], zIndex = q$lid2[pid] + 400)
if (length(groups_radio) > 0L || length(groups_check) > 0L) {
lf = leaflet::addLayersControl(lf, baseGroups = groups_radio, overlayGroups = groups_check, position = tmap:::leaflet_pos(str2pos(o$control.position)), options = leaflet::layersControlOptions(collapsed = o$control.collapse))
lf = leaflet::addLayersControl(lf, baseGroups = groups_radio, overlayGroups = groups_check, position = leaflet_pos(str2pos(o$control.position)), options = leaflet::layersControlOptions(collapsed = o$control.collapse))
} else {
lf
}
Expand Down
4 changes: 2 additions & 2 deletions R/tmap_arrange.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ print_tmap_arrange <- function(tms, knit = FALSE, show = TRUE, add.titles = TRUE
#tmp <- tempfile(fileext = ".png")
#png( tmp, width=700, height=700, res = 100)

curdev <- dev.cur()
curdev <- grDevices::dev.cur()
rmc = tmap_options(raster.max.cells = 36)
tasps <- suppressMessages({
vapply(tms, function(tm) {
Expand All @@ -81,7 +81,7 @@ print_tmap_arrange <- function(tms, knit = FALSE, show = TRUE, add.titles = TRUE
}, numeric(1))
})

dev.set(curdev)
grDevices::dev.set(curdev)
tmap_options(rmc)

#dev.off()
Expand Down
2 changes: 1 addition & 1 deletion R/tmap_save.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ tmap_save = function(tm=NULL, filename=NA, device=NULL, width=NA, height=NA, uni

if (!is.arrange && !missing(insets_tm) && !missing(insets_vp)) {
args_inset = if (!is.na(scale)) list(scale = scale) else list()
if (class(insets_tm)=="list" && class(insets_vp)=="list") {
if (is(insets_tm, "list") && is(insets_vp, "list")) {
if (length(insets_tm) != length(insets_vp)) stop("Number of insets unequal to number of viewports")
mapply(function(tm_i, vp_i) {
print(tm_i + do.call("tm_layout", args_inset), vp=vp_i)
Expand Down
34 changes: 19 additions & 15 deletions examples/tm_layout.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
data(land, World)

tm_shape(land) +
tm_raster("elevation",
col.scale = tm_scale_intervals(breaks = c(-Inf, 250, 500, 1000,
1500, 2000, 2500, 3000, 4000, Inf),
values = terrain.colors(9), midpoint = NA),
col.legend = tm_legend(title = "Elevation", position = tm_pos_in("left", "bottom"),
frame = TRUE, bg.color = "lightblue")) +
tm_shape(World, is.main = TRUE, crs = "+proj=eck4") +
tm_borders("grey20") +
tm_graticules(labels.size = .5) +
tm_text("name", size="AREA") +
#tm_compass(position = c(.65, .15), color.light = "grey90") +
#tm_credits("Eckert IV projection", position = c("right", "BOTTOM")) +
tm_style("classic_v3") +
tm_layout(bg.color = "lightblue", inner.margins = c(0, 0, .02, 0))
tm_raster(
"elevation",
col.scale = tm_scale_intervals(
breaks = c(-Inf, 250, 500, 1000, 1500, 2000, 2500, 3000, 4000, Inf),
values = terrain.colors(9), midpoint = NA
),
col.legend = tm_legend(
title = "Elevation", position = tm_pos_in("left", "bottom"),
frame = TRUE, bg.color = "lightblue"
)
) +
tm_shape(World, is.main = TRUE, crs = "+proj=eck4") +
tm_borders("grey20") +
tm_graticules(labels.size = .5) +
tm_text("name", size = "AREA") +
# tm_compass(position = c(.65, .15), color.light = "grey90") +
# tm_credits("Eckert IV projection", position = c("right", "BOTTOM")) +
tm_style("classic_v3") +
tm_layout(bg.color = "lightblue", inner.margins = c(0, 0, .02, 0))

data(land, World)

Expand Down
13 changes: 10 additions & 3 deletions examples/tm_symbols.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@ if (require(ggplot2) && require(dplyr) && require(tidyr) && require(tmaptools) &

origin_data <- NLD_prov %>%
st_set_geometry(NULL) %>%
mutate(FID= factor(1:n())) %>%
select(FID, origin_native, origin_west, origin_non_west) %>%
gather(key=origin, value=perc, origin_native, origin_west, origin_non_west, factor_key=TRUE)
dplyr::mutate(FID= factor(1:dplyr::n())) %>%
dplyr::select(FID, origin_native, origin_west, origin_non_west) %>%
tidyr::pivot_longer(
cols = c(origin_native, origin_west, origin_non_west),
names_to = "origin",
values_to = "perc",
names_transform = as.factor
) %>%
dplyr::arrange(origin, FID) %>%
as.data.frame()

origin_cols <- get_brewer_pal("Dark2", 3)

Expand Down
34 changes: 19 additions & 15 deletions man/tm_layout.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions man/tm_symbols.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5df6369

Please sign in to comment.