0

I want to use functions from the expss package in my own functions/packages. I usually call the functions along with their packages (e.g. dplyr::mutate(...)).

The expss package has a function/operator %to%, and I don't know how I can do the same here, i.e. expss::%to% doesn't work, neither does expss::'%to%'.

What can I do?

deschen
  • 10,012
  • 3
  • 27
  • 50

1 Answers1

3

Infix operators must be attached to be usable; you can’t use them prefixed with the package name.1

Inside a package, the conventional way is to add an importFrom directive to your NAMESPACE file or, if you’re using ‘roxygen2’, add the following Roxygen directive somewhere:

#' @importFrom expss %to%

Outside of package code, you could use ‘box’ to attach just the operator:

box::use(expss[`%to%`])

Or you can use simple assignment (this is the easiest solution in the simplest case but it becomes a lot of distracting code for multiple operators):

`%to%` = expss::`%to%`

1 Except using regular function call syntax:

expss::`%to%`(…)
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
  • Thanks, the easy ``%to%` = expss::`%to%`` works in my case for testing purposes. For package usage I will use the importFrom. – deschen Oct 14 '22 at 08:13
  • You can also do `library(expss, include.only = "%to%")` – moodymudskipper Oct 14 '22 at 16:46
  • @moodymudskipper Kinda, but not really. This functionality is broken: calling it twice in a row with different arguments for the same package will silently ignore the second call. This alone (even ignoring the unergonomic syntax) effectively makes it unusable. By contrast, `box::use()` does the correct thing. – Konrad Rudolph Oct 14 '22 at 21:08