I have seen this occur in a couple of instances but as it is an easy fix, I'd never asked:
- Sometimes the {magrittr}/{dplyr} pipe works differently than if you explicitly supply the input to the RHS function.
- Is this something to do with environments? See the below example where we can fix by either:
- Not using the pipe
- Supplying the environment explicitly (which we shouldn't have to do)
library(dplyr)
iris_test_1 <- iris
iris_test_2 <- iris
iris_test_3 <- iris
iris_test_4 <- iris
# Find objects starting with certain letters in global
# environment (this relies on you having a clean global
# environment)
# Works
ge_datasets <- ls(pattern = "^iris_test_")
mget(ge_datasets) %>%
bind_rows() %>%
as_tibble()
# Doesn't work
ls(pattern = "^iris_test_") %>%
mget() %>%
bind_rows() %>%
as_tibble()
# Works
ls(pattern = "^iris_test_") %>%
mget(.GlobalEnv) %>%
bind_rows() %>%
as_tibble()