sebastianmm
sebastianmm

Reputation: 1176

Error in as(data, "transactions"): no method or default for coercing “data” to “transactions”

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?

Upvotes: 0

Views: 5470

Answers (1)

sebastianmm
sebastianmm

Reputation: 1176

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.

Upvotes: 1

Related Questions