2

From this tutorial, I understand that pipes "take the output of one statement and make it the input of the next statement."

Can I select a piece of an output and make it an input of the next statement? For example, I'd like to know where the outliers are in this dataset :

mtcars$mpg %>% boxplot()$outliers %>% which

Thanks!

Slash
  • 501
  • 2
  • 9
  • ```mtcars$mpg %>% boxplot() %>% `[[`("out")``` – M-- Mar 15 '19 at 16:37
  • 5
    Load magrittr and use a dollar pipe `mtcars %$% mpg %>% boxplot %$% out`. See https://stackoverflow.com/q/21618423 – Frank Mar 15 '19 at 16:49
  • @Frank amazing. I get `Error in FUN(X[[i]], ...) : lazy-load database` when loading `magrittr` tho – M-- Mar 15 '19 at 16:54
  • @M-M Hm, that's not good. Maybe retry in a new R session (and maybe also after reinstalling magrittr)? – Frank Mar 15 '19 at 16:58
  • @Frank Tried that already. That error has been with me for the past couple of weeks. I guess I should reinstall R altogether. – M-- Mar 15 '19 at 16:59
  • 1
    Btw, the nice tutorial OP links includes `%$%` starting under "Additional pipes" – Frank Mar 15 '19 at 17:09

1 Answers1

3

you can use purrr::pluck()

mtcars$mpg %>% boxplot() %>% purrr::pluck("out")

depending on the output type of the function, you can also use [

mtcars$mpg %>% boxplot() %>% .[["out"]]
Wil
  • 3,076
  • 2
  • 12
  • 31