0

Within a little script I wrote, I successfully call

library(arules)
trans <- as(data, "transactions")

Now I want to include this in a function in my R package. arules is imported, and I call the arules functions using ::. However, as does not work. It gives me the above error message, which suggests that it does not know how to handle transactions. And there is no as.transactions, or similar in the arules package that I could import.

This answer shows how to import an operator from a package. I assume there is something similar for my problem, I just don't know what to look for.

What do I have to do in order for as to understand what transactions are?

Community
  • 1
  • 1
sebastianmm
  • 1,148
  • 1
  • 8
  • 26
  • `as` redirects to `as.transactions` if such a function exists. If you want `as` to work here, you must write a function named that (consistent with whatever object-oriented stuff is required). Maybe you should just use whatever constructor there is for transactions instead of coercing. – Frank Apr 05 '16 at 16:42
  • 1
    Like I said, there is no `as.transactions` defined anywhere. The functionality is achieved implementing a `setAs` function. See my answer below for details. – sebastianmm Apr 05 '16 at 21:06
  • Ok, nice find. This is over my head. – Frank Apr 05 '16 at 21:07

1 Answers1

2

After some more searching, I found the answer in Hadley Wickham's Advanced R. transactions is an S4 class, as can be seen in arules' source. To import an S4 class, we simply put a roxygen-style @importClassesFrom above the head of the function we are using the class in.

#' @importClassesFrom arules transactions

One might also have to add the methods package to the imports, as the S4 functionality is implemented there.

sebastianmm
  • 1,148
  • 1
  • 8
  • 26