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?

3
  • 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 5, 2016 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. Apr 5, 2016 at 21:06
  • Ok, nice find. This is over my head.
    – Frank
    Apr 5, 2016 at 21:07

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.