File: asJSON.difftime.R

package info (click to toggle)
r-cran-jsonlite 1.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,340 kB
  • sloc: ansic: 3,792; sh: 9; makefile: 6
file content (13 lines) | stat: -rw-r--r-- 353 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
setMethod("asJSON", "ts", function(x, ...) {
  asJSON(as.vector(x), ...)
})

setMethod("asJSON", "hms", function(x, hms = c("string", "secs"), ...) {
  hms <- match.arg(hms)
  output <- switch(hms,
                   string = as.character(x),
                   secs = as.numeric(x, units = "secs")
  )
  output[is.na(x)] <- NA
  asJSON(output, ...)
})