4

my objective is to apply association rules for text mining.

i have this sample of strings:

sample.word = c("abstracting","abstracting workflow","access control","access information","access methods","access patterns","access permissions","access to government information","accountability","acetamides")

than i make a matrix with all values 0

incidence.matrix_sample <- matrix(0, nrow=5, ncol=length(sample.word))

i add strings as matrix column

colnames(incidence.matrix_sample) <- sample.word

now i put 1 value in the column of terms that appear in document using pmatch function (documents.ids[[i]] is a vector with id of document)

for(i in 1:(dim(incidence.matrix_sample)[1]))
{
  incidence.matrix_sample[i, pmatch(documents.ids[[i]], sample.word)] <- 1
}

i try to go on and transform my matrix first as itemMatrix and then as transactions (with as(my.matrix, "transactions") function) but when i try to inspect rules i get the same error:

incidence.matrix_sample <- as(incidence.matrix_sample, "itemMatrix")
incidence.matrix_sample <- as(incidence.matrix_sample, "transactions")
inspect(incidence.matrix_sample)

the result is:

Errore in UseMethod("inspect", x) : 
  no applicable method for 'inspect' applied to an object of class "c('matrix', 'double', 'numeric')"

and the same problems using apriori function to incidence.matrix_sample

Errore in UseMethod("inspect", x) : 
  no applicable method for 'inspect' applied to an object of class "c('rules', 'associations')"

are days that i'm trying to understand where is the problem.. can someone help me?

ntrax
  • 457
  • 4
  • 22
  • Read first http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example, post later. – zero323 Sep 21 '13 at 15:11
  • `inspect` is an S4 method provided by the `arules` package, but your error messages suggest you have an S3 method with the same name, probably from another package. If you do not load that other package, or if you explicitly specify the namespace (`arules::inspect`), the problem should disappear. – Vincent Zoonekynd Sep 21 '13 at 15:21
  • thanks for reply but i try with arules::inspect but seems doesn't work – ntrax Sep 21 '13 at 16:21
  • the problem is this ... tm and arules packages has inspect method.. so before using arules i need to detach tm package: detach(package:tm, unload=TRUE) and then load arules thanks for the help – ntrax Sep 21 '13 at 17:12

3 Answers3

10

The rason of this error is that both arules and tm library has inspect() method and so the order in which they are loaded affects how this method is implemented.

The way to solve this problem is to detach a library before using inspect() method for an object made with other library. For example, after getting incidence matrix i need to detach tm package :

detach(package:tm, unload=TRUE)

then load arules library and use inspect() method for an arules object.

I hope it's useful

ntrax
  • 457
  • 4
  • 22
3

You can use arules::inspect(incidence.matrix_sample)

:: specifies which library to use

DataTx
  • 1,839
  • 3
  • 26
  • 49
0

function inspect used by both library tm and arules, you just need to specify which library is suitable to the object u want to inspect

  • arules::inspect(incidence.matrix_sample)
  • tm::inspect(corpus)