R/colours.R

Defines functions appendAlpha isHexColour

isHexColour <- function(cols){
  hexPattern <- "^#(?:[0-9a-fA-F]{3}){1,2}$|^#(?:[0-9a-fA-F]{4}){1,2}$"
  all(grepl(hexPattern, cols))
}

appendAlpha <- function( col ) {
	if( isHexColour( col ) ) {
		col <- unname(
			vapply(col, function(x) {
				ifelse(
					nchar(x) == 4
					, paste0(x, "F")
					, ifelse(
						nchar(x) == 7
						, paste0(x, "FF")
						, x
						)
					)
				},"" )
		)
	}
	return( col )
}

Try the mapdeck package in your browser

Any scripts or data that you put into this service are public.

mapdeck documentation built on Sept. 4, 2020, 9:07 a.m.