So, I have a tibble containing both vector- and list-columns.
Selecting list-columns is easy with dplyr:
select_if(tb, is.list)
but its negation with !
or -
does not work edit, this does select_if(tb,function(x)!is.list(x))
So I thought I could do something like:
select(tb, which(!apply(tb,2,is.list))
This returns no columns. Because apparently (here comes the reprex), is.list
on tibble columns always returns true, even for vector columns (?).
df <- data.frame(A = runif(100))
tb <- tibble(A = runif(100))
is.list(df$A)
# FALSE
is.list(tb$A)
# FALSE
is.list(df[,1])
# FALSE
is.list(tb[,1])
# TRUE
Can anybody shed light on what is going on here?
Because tibble has default drop argument as FALSE
meaning when you subset only one column from dataframe it returns a numeric vector whereas when you subset one column from tibble it returns a one-column tibble.
Check their classes.
class(df[, 1])
#[1] "numeric"
class(tb[, 1])
#[1] "tbl_df" "tbl" "data.frame"
If you add drop = FALSE
in dataframe, it will return you back a dataframe.
class(df[, 1, drop = FALSE])
#[1] "data.frame"
A dataframe/tibble column is still a list.
is.list(tb[, 1])
#[1] TRUE
is.list(df[, 1, drop = FALSE])
#[1] TRUE
So to answer your question yes, is.list
always returns TRUE
on tibble unless you explicitly mention drop = TRUE
on one-column tibble.
is.list(tb[, 1, drop = TRUE])
#[1] FALSE
1