Ok, it's late, and I feel like I'm missing something really fundamental.
Why is this happening?
# example, I'm going to make a list that had three data_frames or tibble
library(dplyr)
library(purrr)
a <- data.frame(
foo = letters[1:10],
bar = seq(1:10)
)
b <- data.frame(
foo = letters[1:5],
bar = seq(1:5)
)
c <- data.frame(
foo = character(),
bar = integer()
)
li <- list(
A = a, B = b, C = c
)
# So, what I want to do is print the name of list and a short message for those that have data
# yes, I know there are other (better) ways, but this is just me simplifying a much bigger thing I'm actually working with
# I expect to get this:
# "A has data!"
# "B has data!"
li %>% keep(~nrow(.) > 0) %>% names() %>% map(~print(paste0(.," has data!")))
Instead I got this:
[1] "A has data!"
[1] "B has data!"
[[1]]
[1] "A has data!"
[[2]]
[1] "B has data!"
So I broke it down a bit
keepThese <- li %>% keep(~nrow(.) > 0)
keepThese
# Yep, that's what I expected
keepThese.names <- keepThese %>% names()
keepThese.names
str(keepThese.names)
# Yep again, what I also expected, a character vector of "A", "B"
#let's try again
keepThese.names %>% map(~print(paste0(.," has data!")))
[1] "A has data!"
[1] "B has data!"
[[1]]
[1] "A has data!"
[[2]]
[1] "B has data!"
Same thing? Why?