-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.R
More file actions
45 lines (40 loc) · 1.23 KB
/
utils.R
File metadata and controls
45 lines (40 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
is_logical <- function(x) {
is.logical(x) && length(x) && !is.na(x)
}
format_dates <- function(x) {
fechas_metadatos <- startsWith(colnames(x), "fecha_")
x[fechas_metadatos] <- lapply(x[fechas_metadatos],
as.POSIXct, format = "%Y%m%d%H%M%S",
tz = "CET")
if (!is.null(x$fecha_disposicion)) {
x$fecha_disposicion <- as.Date(x$fecha_disposicion)
}
if (!is.null(x$fecha_publicacion)) {
x$fecha_publicacion <- as.Date(x$fecha_publicacion)
}
x
}
format_date <- function(date){
if (is(date, "Date")) {
date <- format(date, "%Y%m%d")
} else if (is.numeric(date)) {
date <- as.character(date)
}
date
}
check_limit <- function(limit) {
if (!is.numeric(limit)) {
stop("Limit must be a numeric number from -1 to higher numbers", call. = FALSE)
}
if (limit < -1L) {
stop("Limit can only be between [-1, Inf]", call. = FALSE)
}
}
check_offset <- function(offset) {
if (!is.numeric(offset)) {
stop("Offset must be a numeric number higher than 1.", call. = FALSE)
}
if (offset <= 0L) {
stop("Offset must be a postivie number", call. = FALSE)
}
}