0

I'm trying to adjust a function I've written to explicitly call on other packages using "::", e.g., dplyr::mutate. However, adding the "::" doesn't work for the pipe operator %>%. How do I call on that?

This does not work:

  DF <- data.frame(A = LETTERS[1:4],
             B = 1:4) magrittr::%>% 
  dplyr::mutate(C = 5)

The error I receive is "Error in mutate_(.data, .dots = compat_as_lazy_dots(...)) : argument ".data" is missing, with no default", so I think that means it's not getting the input of the left-hand data.frame to pipe into the function mutate.

shirewoman2
  • 1,842
  • 4
  • 19
  • 31

1 Answers1

-1

I should be:

magrittr::`%>%`()
  • When I tried `DF <- data.frame(A = LETTERS[1:4], B = 1:4) magrittr::\`%>%\`(dplyr::mutate(C = 5))`, that gives me an "unexpected symbol" error. – shirewoman2 Oct 17 '20 at 00:46
  • 1
    @shirewoman2 You can't pipe if you use ```magrittr::`%>%```. You have to do ```magrittr::`%>%(left, right)```. So you lose the interest of the pipe operator... – Stéphane Laurent Oct 17 '20 at 00:53
  • Darn. I use the pipe extensively. No way around it, then? – shirewoman2 Oct 17 '20 at 00:58
  • 1
    @shirewoman2 Don't use `::`, simply. Why do you do that? And you could even avoid the pipe operator for programming, because it is slow. But well, it is nice for readibility, I know. – Stéphane Laurent Oct 17 '20 at 01:17
  • @StéphaneLaurent :-) For the `::`, I'm following the advice from here for writing a package: https://r-pkgs.org/namespace.html. For the `%>%`, yes, I like it for readability. Thanks, though! – shirewoman2 Oct 17 '20 at 01:30
  • @shirewoman2 This advice is for the readability only. Because with `::`, the reader knows from which package the function comes from. But everybody knows the pipe operator these days. Moreover using `::` is ugly. – Stéphane Laurent Oct 17 '20 at 02:36