forked from tidyverse/dplyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrbind.R
59 lines (48 loc) · 1.14 KB
/
rbind.R
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
list_or_dots <- function(...) {
dots <- list2(...)
if (!length(dots)) {
return(dots)
}
# Old versions specified that first argument could be a list of
# dataframeable objects
if (is_list(dots[[1]])) {
dots[[1]] <- map_if(dots[[1]], is_dataframe_like, as_tibble)
}
# Need to ensure that each component is a data frame or a vector
# wrapped in a list:
dots <- map_if(dots, is_dataframe_like, function(x) list(as_tibble(x)))
dots <- map_if(dots, is_atomic, list)
dots <- map_if(dots, is.data.frame, list)
unlist(dots, recursive = FALSE)
}
is_dataframe_like <- function(x) {
if (is_null(x)) {
return(FALSE)
}
# data frames are not data lists
if (is.data.frame(x)) {
return(FALSE)
}
# Must be a list
if (!is_list(x)) {
return(FALSE)
}
# 0 length named list (#1515)
if (!is_null(names(x)) && length(x) == 0) {
return(TRUE)
}
# With names
if (!is_named(x)) {
return(FALSE)
}
# Where each element is an 1d vector or list
if (!every(x, is_1d)) {
return(FALSE)
}
# All of which have the same length
n <- lengths(x)
if (any(n != n[1])) {
return(FALSE)
}
TRUE
}