SymbolixAU / mapdeck
1
# Check Hex
2
#
3
# Checks if the paramter is a hex colour
4
# @param arg
5
checkHex <- function(arg) {
6 1
	if(!is.null(arg)) {
7 1
		if(!isHexColour(arg))
8 1
			stop(paste0(deparse(substitute(arg)), " must be a valid hex colour"))
9
	}
10
}
11

12
# Check Hex Alpha
13
# checks if the paramter is HEX AND has the alpha component
14
checkHexAlpha <- function(arg) {
15 1
	checkHex(arg)
16 1
	if(!nchar(arg) %in% c(9)) {
17 0
		stop(paste0(deparse(substitute(arg)), " must be a valid hex colour with an alpha component"))
18
	}
19
}
20

21

22
# Check Palette
23
#
24
# Checks if the palette supplied is a function
25
# @param arg
26
checkPalette <- function(arg) {
27 1
	if(!is.null(arg)) {
28 1
		if(!is.function(arg))
29 1
			stop(paste0(deparse(substitute(arg)), " must be a function which generates hex colours"))
30
	}
31
}
32

33
# Check Numeric
34
#
35
# Checks the argument is length 1 numeric
36
# @param arg
37
checkNumeric <- function(arg) {
38 1
	if(!is.null(arg)) {
39 1
		if(!is.numeric(arg) | length(arg) != 1)
40 1
			stop(paste0(deparse(substitute(arg)), " must be a single numeric value"))
41
	}
42
}
43

44

45

46
# Is Using Polyline
47
#
48
# Checks if the polyline argument is null or not
49
# @param polyline
50
isUsingPolyline <- function(polyline){
51 0
	if(!is.null(polyline)) return(TRUE)
52 0
	return(FALSE)
53
}
54

55
# Unlist Multi Polyline
56
#
57
# unlists a polyline column so it's one row per geometry
58
#
59
# @param df
60
# @param geometry
61
unlistMultiGeometry <- function( df, geometry ) {
62

63 1
	list_length <- vapply( df[[ geometry ]] , length, 1L)
64 1
	unlisted <- unlist( df[[ geometry ]] )
65 1
	df_rows <- 1:nrow(df)
66

67
	## ensure a one-column data.frame is handle correctly
68 1
	df <- df[rep(df_rows, list_length), setdiff(names(df), geometry), drop = F]
69 1
	df[[ geometry ]] <- unlisted
70 1
	return( df )
71
}

Read our documentation on viewing source code .

Loading