View source: R/class-glatos_animals.r
glatos_animals | R Documentation |
Creates, checks, or validates a glatos_animals object.
glatos_animals(..., validate = TRUE)
as_glatos_animals(x, validate = TRUE)
is_glatos_animals(x)
validate_glatos_animals(x)
... |
Named vectors, minimally one for each required column of the specified class:
|
validate |
logical, indicates if column names and classes should be checked against requirements. |
x |
A data.frame or object that inherits from data.frame (e.g.,
data.table, tibble) and contains all required columns (see |
glatos_animals()
creates a glatos_animals
from
individual vectors (one for each column) and optionally checks for required
column names and classes using validate_glatos_animals()
.
as_glatos_animals()
coerces a data.frame, or object that
inherits from data.frame, to glatos_animals
and optionally checks for
required column names and classes using validate_glatos_animals()
.
is_glatos_animals()
checks class attribute for "glatos_animals"
validate_glatos_animals()
checks for required column names and classes
# glatos_animals
x <- data.frame(
animal_id = c("120", "107", "109"),
tag_id_code = c("32024", "32012", "32014"),
tag_code_space = c("A69-9001", "A69-9001", "A69-9001"),
utc_release_date_time = as.POSIXct(
c(
"2011-03-28 00:00:00",
"2011-03-28 00:01:00",
"2011-03-28 00:05:00"
),
tz = "UTC"
),
release_latitude = c(41.56093, 41.56093, 41.56093),
release_longitude = c(-83.645, -83.645, -83.645)
)
ga_df1 <- glatos_animals(
animal_id = x$animal_id,
tag_id_code = x$tag_id_code,
tag_code_space = x$tag_code_space,
utc_release_date_time = x$utc_release_date_time
)
# as_glatos_animals
ga_df2 <- as_glatos_animals(x)
# sf input
library(sf)
x_sf <- sf::st_as_sf(x,
coords = c("release_longitude", "release_latitude")
)
ga_sf <- as_glatos_animals(x_sf)
# tibble input
x_tbl <- dplyr::as_tibble(x)
ga_tbl <- as_glatos_animals(x_tbl)
# All below will error as invalid
# data.frame input; missing column name
library(dplyr) # for rename
x2 <- rename(x,
fish_name = animal_id,
release_timestamp = utc_release_date_time
)
try(
ga2 <- as_glatos_animals(x2)
)
# data.frame input; wrong column class
x3 <- mutate(x,
animal_id = as.integer(animal_id),
utc_release_date_time = as.character(utc_release_date_time)
)
try(
ga3 <- as_glatos_animals(x3)
)
# Validation and checking
validate_glatos_animals(x)
is_glatos_animals(x) # FALSE
is_glatos_animals(ga_df1) # TRUE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.