File: is.recordlist.R

package info (click to toggle)
r-cran-jsonlite 1.7.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,320 kB
  • sloc: ansic: 3,792; sh: 9; makefile: 2
file content (26 lines) | stat: -rw-r--r-- 600 bytes parent folder | download | duplicates (6)
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
#' @useDynLib jsonlite C_is_recordlist
is_recordlist_c <- function(x){
  .Call(C_is_recordlist, x)
}

is_recordlist_r <- function(x) {
  if (!(is.unnamedlist(x) && length(x))) {
    return(FALSE)
  }
  at_least_one_object = FALSE
  for(i in x){
    if(!(is.namedlist(i) || is.null(i))) return(FALSE)
    if(!at_least_one_object && is.namedlist(i)) at_least_one_object <- TRUE
  }
  return(at_least_one_object)
}

is.recordlist <- is_recordlist_c;

is.namedlist <- function(x) {
  isTRUE(is.list(x) && !is.null(names(x)))
}

is.unnamedlist <- function(x) {
  isTRUE(is.list(x) && is.null(names(x)))
}