Skip to content

Commit

Permalink
📝 Update documents for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
NONONOexe committed Sep 16, 2024
1 parent 8c17d41 commit 7673e77
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 25 deletions.
46 changes: 25 additions & 21 deletions R/create-spatiotemporal-event.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,60 @@
#' a given `sf` object, allowing spatial and temporal data to be
#' handled together.
#'
#' @name create_spatiotemporal_event
#' @param x A `sf` object representing the spatial data.
#' @param time_column_name A character string specifying the column name
#' in `x` that contains time-related data. Defaults to `"time"`
#' @param time_format A character string specifying the format of
#' the time data in the `time_column_name`. For example, you can
#' use formats like `"%Y-%m-%d"` for dates or `"%H:%M:%S"` for time.
#' Defaults to `"%H"`.
#' @param ... Additional arguments passed to or from other methods.
#' @return An `sf` object with class `spatiotemporal_event` added,
#' representing a spatiotemporal event collection.
#' @name spatiotemporal_event
#' @aliases create_spatiotemporal_event
#' @export
#' @examples
#' # Simple feature collection object representing accidents
#' sample_accidents
#'
#' # Create a spatiotemporal event collection
#' create_spatiotemporal_event(sample_accidents)
NULL

#' @rdname create_spatiotemporal_event
#' @export
create_spatiotemporal_event <- function(x, ...) {
UseMethod("create_spatiotemporal_event")
}

#' @rdname create_spatiotemporal_event
#' @param time_column_name A character string specifying the column name
#' in `x` that contains time-related data. Defaults to `"time"`
#' @param time_format A character string specifying the format of
#' the time data in the `time_column_name`. For example, you can
#' use formats like `"%Y-%m-%d"` for dates or `"%H:%M:%S"` for time.
#' Defaults to `"%H"`.
#' @rdname spatiotemporal_event
#' @export
create_spatiotemporal_event.sf <- function(x,
time_column_name = "time",
time_format = "%H",
...) {
attributes(x)$class <- c("spatiotemporal_event",
"sf",
"data.frame")
attributes(x)$class <- c("spatiotemporal_event", "sf", "data.frame")
attr(x, "time_column") <- time_column_name
attr(x, "time_format") <- time_format

return(x)
}

#' @rdname create_spatiotemporal_event
#' Print a spatiotemporal event collection
#'
#' This function prints a summary of a spatiotemporal event collection object.
#'
#' @param x A `spatiotemporal_event` object.
#' @param ... Additional arguments passed to or from other methods.
#' @return The `spatiotemporal_event` object, invisibly.
#' @export
#' @examples
#' spatiotemporal_events <- create_spatiotemporal_event(sample_accidents)
#' print(spatiotemporal_events)
print.spatiotemporal_event <- function(x, ...) {
cat("Spatiotemporal event collection with",
nrow(x), "events and", ncol(x) - 2, "fields\n")
cat("Geometry type:", as.character(unique(st_geometry_type(x))), "\n")
cat("Time column: ", attr(x, "time_column"), "\n")
cat("Time format: ", attr(x, "time_format"), "\n")
cat("Data:\n")
nrow(x), "events and", ncol(x) - 2, "fields", fill = TRUE)
cat("Geometry type:", as.character(unique(st_geometry_type(x))), fill = TRUE)
cat("Time column: ", attr(x, "time_column"), fill = TRUE)
cat("Time format: ", attr(x, "time_format"), fill = TRUE)
cat("Data:", fill = TRUE)
print(as.data.frame(x)[1:5, ])
if (5 < nrow(x)) cat("...", nrow(x) - 5, "more events\n")

Expand Down
23 changes: 23 additions & 0 deletions man/print.spatiotemporal_event.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7673e77

Please sign in to comment.