R/messages.R

Defines functions message_pos_auto message_wrapstack message_nothing_to_show message_c4a message_comp_high_wide message_comp_scale message_reg message_thrown message_init

message_init = function() {
	.TMAP$messages = character()
	invisible(NULL)
}

message_thrown = function(id) {
	id %in% .TMAP$messages
}

message_reg = function(id) {
	.TMAP$messages = c(.TMAP$messages, id)
	NULL
}

message_comp_scale = function() {
	if (!message_thrown("comp_scale")) {
		message("[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.")	
		message_reg("comp_scale")
	}
	NULL
}

message_comp_high_wide = function(stack) {
	if (!message_thrown("comp_scale")) {
		message("[plot mode] legend/component: Some components or legends are too ", ifelse(stack == "vertical", "high", "wide"), " and are therefore rescaled. Set the tmap option 'component.autoscale' to FALSE to disable rescaling.")	
		message_reg("comp_scale")
	}
	NULL
}

message_c4a = function(old_palette_name, info) {
	new1 = info$fullname
	new2 = info$name
	mess = 	paste0("c4a_", old_palette_name)

	if (!message_thrown(mess)) {
		message(paste0("[cols4all] color palettes: use palettes from the R package cols4all. Run 'cols4all::c4a_gui()' to explore them. The old palette name \"", old_palette_name, "\" is named \"", new2, "\" (in long format \"", new1, "\")"))
		message_reg(mess)	
	} 
}

message_nothing_to_show = function(any_groups) {
	if (any_groups) {
		message("[nothing to show] no data layers defined after tm_shape")
	} else {
		message("[nothing to show] no layers defined")
	}
	NULL
}

message_wrapstack = function(horizontal = TRUE) {
	if (horizontal) {
		message("[facets] use tm_facets_hstack() instead of tm_facets_wrap() to put the legends next to and aligned with the facets")
	} else {
		message("[facets] use tm_facets_vstack() instead of tm_facets_wrap() to put the legends next to and aligned with the facets")
	}
	NULL
}

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()"
		message("[position] ", "use ", fun2, " instead of ", fun, ". The latter should be used with tmap_options().")
		message_reg("pos_auto")
	}
	NULL	
}
r-tmap/tmap documentation built on June 23, 2024, 9:58 a.m.