Skip to content

Commit

Permalink
Resolve package check issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
henningte committed Nov 30, 2021
1 parent 46b4701 commit 5cb11ca
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ packrat/lib*/
.RData
.Ruserdata
sftime.Rproj
inst/doc
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Description: Provides classes and methods for spatial objects that have a regist
Version: 0.2-0
Depends: sf
Imports: methods
Suggests: knitr, spacetime
Suggests:
knitr,
spacetime,
rmarkdown
Authors@R:
c(person(given = "Edzer",
family = "Pebesma",
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ S3method(plot,sftime)
S3method(print,sftime)
S3method(print,tc)
S3method(st_as_sftime,ST)
export(is_sortable)
export(st_as_sftime)
export(st_get_time)
export(st_sftime)
Expand Down
2 changes: 1 addition & 1 deletion R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#' g = st_sfc(lapply(1:50, function(i) st_point(coords[i,]) ))
#' sf <- st_sf(a=1:50, g)
#'
#' sft <- st_sf_time(sf, st_tc(as.POSIXct("2020-09-01 00:00:00")+0:49*3600*6))
#' sft <- st_sftime(cbind(sf, time = st_tc(as.POSIXct("2020-09-01 00:00:00")+0:49*3600*6)))
#' plot(sft)
#'
plot.sftime <- function(x, y, ..., mode="xy", number=6, tcuts, key.pos=-1) {
Expand Down
17 changes: 11 additions & 6 deletions R/sftime.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@
#' these columns shall be a geometry list-column of class \code{sfc} and one
#' shall be a time list-column of class \code{tc}.
#' @param crs Coordinate reference system, something suitable as input to
#' \code{\link{st_crs}}.
#' \code{\link{sf}{st_crs}}.
#' @param agr A character vector; see details below.
#' @param row.names row.names for the created \code{sf} object.
#' @param stringsAsFactors A logical value; see \link{st_read}.
#' @param precision A numeric value; see \link{st_as_binary}
#' @param stringsAsFactors A logical value; see
#' \code{\link{sf}{st_read}}.
#' @param precision A numeric value; see
#' \code{\link{sf}{st_as_binary}}.
#' @param sf_column_name A character value; name of the active list-column with
#' simple feature geometries; in case there is more than one and
#' \code{sf_column_name} is \code{NULL}, the first one is taken.
#' @param tc_column_name A character value; name of the active
#' time column (\code{\link[tc]{tc}} object). In case there is more than one
#' time column (\code{\link[=st_tc]{tc}} object). In case there is more than one
#' \code{tc} object in \code{...} and \code{tc_column_name} is
#' \code{NULL}, the first \code{tc} is taken.
#' @param sfc_last A logical value; if \code{TRUE}, \code{sfc} columns are
#' always put last, otherwise column order is left unmodified.
#' @param tc_last A logical value; if \code{TRUE}, \code{tc} columns are always
#' put last, otherwise column order is left unmodified. If both \code{sfc_last}
#' and \code{tc_last} are \code{TRUE}, \code{tc} columns are put last.
#' @param check_ring_dir A logical value; see \link{st_read}.
#' @param check_ring_dir A logical value; see \code{\link{sf}{st_read}}.
#'
#' @return An object of class \code{sftime}.
#' @examples
Expand All @@ -35,7 +37,9 @@
#' st_sftime(a = 3, g, time = tc)
#'
#' ## construction with an sf object
#' \dontrun{st_sftime(st_sf(a = 3, g), time = tc) # error, because if ... contains a data.frame-like object, no other objects may be passed through ... . Instead, add the time column before.}
#' \dontrun{st_sftime(st_sf(a = 3, g), time = tc)
#' # error, because if ... contains a data.frame-like object, no other objects
#' # may be passed through ... . Instead, add the time column before.}
#' st_sftime(st_sf(a = 3, g, time = tc))
#' @export
st_sftime <- function(...,
Expand Down Expand Up @@ -66,6 +70,7 @@ st_sftime <- function(...,
sfc_last = sfc_last)

# search time column(s)
all_tc_names <- NULL
all_tc_columns <- vapply(res, function(x) inherits(x, "tc"), TRUE)
if(!any(all_tc_columns)) stop("No time column found.")
all_tc_columns <- which(unlist(all_tc_columns))
Expand Down
10 changes: 6 additions & 4 deletions R/tc.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#' @name is_sortable
#' @param x The object to check.
#' @return \code{TRUE} if \code{x} passes the check, else \code{FALSE}.
#' @keywords internal
#'
#' @details Checks whether the provided object can be handled by
#' \code{\link{order}}. A couple of basic types are whitelisted. However, custom
Expand All @@ -21,6 +22,7 @@
#' is_sortable(x)
#'
#' @importFrom utils methods
#' @export
is_sortable <- function(x) {
# can x be sorted?
# sort.default checks 'is.object(x)' and uses 'order' to subset and sort the object
Expand All @@ -34,15 +36,15 @@ is_sortable <- function(x) {
# sort(x)
# order(x)
# class(x)
any(vapply(class(x), function(clsnm) clsnm %in% c("numeric", "POSIXct", "POSIXlt", "Date", "yearmon", "yearqtr", "factor"), TRUE)) || # have a list of wellknown exceptions
paste("xtfrm", class(x), sep=".") %in% methods(class = class(x)) # check for function 'xtfrm.[CLASSNAME]' which is used by 'order' which in turn is used by sort.default
any(vapply(class(x), function(y) y %in% c("numeric", "POSIXct", "POSIXlt", "Date", "yearmon", "yearqtr", "factor"), TRUE)) || # have a list of wellknown exceptions
any(vapply(class(x), function(y) paste("xtfrm", y, sep=".") %in% methods(class = y), TRUE)) # check for function 'xtfrm.[CLASSNAME]' which is used by 'order' which in turn is used by sort.default

}

#' Construct a \code{tc} object from a vector with time information
#'
#' An object of class \code{tc} stores time information and can be used as
#' time column in a \code{\link[sftime:st_sftime]{sftime}} object.
#' time column in a \code{\link[=st_sftime]{sftime}} object.
#'
#' @param x A vector or list.
#'
Expand All @@ -58,7 +60,7 @@ st_tc <- function(x) {

#' Subsetting of \code{tc} objects
#'
#' @param x The \code{\link{tc}} object to be subsetted.
#' @param x The \code{\link[=st_tc]{tc}} object to be subsetted.
#' @param i Any subsetting expression supported by the temporal class provided
#' by the \code{tc} object.
#' @param ... any further arguments for the underlying subsetting method.
Expand Down
1 change: 1 addition & 0 deletions man/is_sortable.Rd

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

2 changes: 1 addition & 1 deletion man/plot.sftime.Rd

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

16 changes: 10 additions & 6 deletions man/st_sftime.Rd

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

2 changes: 1 addition & 1 deletion man/st_tc.Rd

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

2 changes: 1 addition & 1 deletion man/sub-.tc.Rd

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

2 changes: 2 additions & 0 deletions vignettes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.html
*.R
15 changes: 11 additions & 4 deletions vignettes/sftime_basics.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,25 @@ sort(tc)[1]

## -----------------------------------------------------------------------------
g = st_sfc(st_point(1:2), st_point(c(1,3)), st_point(2:3), st_point(c(2,1)))
sf <- st_sf(a=1:4, g)

sft <- st_sf_time(sf, sort(tc))
# provide as.data.frame method. This is needed for sf::st_sf to not cause an error with lists when calling as.data.frame
as.data.frame.intervals <- function(x, ...) {
nm <- deparse1(substitute(x))
if (!"nm" %in% names(list(...)))
as.data.frame.vector(x, ..., nm = nm)
else as.data.frame.vector(x, ...)
}

sft <- st_sftime(a = 1:4, g, time = sort(tc))

sft <- st_sf_time(sf, st_tc(Sys.time()-0:3*3600*24))
sft <- st_sftime(g, time = st_tc(Sys.time()-0:3*3600*24))

## ---- fig.width=7-------------------------------------------------------------
coords <- matrix(runif(100), ncol = 2)
g = st_sfc(lapply(1:50, function(i) st_point(coords[i,]) ))
sf <- st_sf(a=1:50, g)

sft <- st_sf_time(sf, st_tc(as.POSIXct("2020-09-01 00:00:00")+0:49*3600*6))
sft <- st_sftime(cbind(sf, time = st_tc(as.POSIXct("2020-09-01 00:00:00")+0:49*3600*6)))

plot(sft, key.pos = 4)

Expand Down

0 comments on commit 5cb11ca

Please sign in to comment.