Search code examples
rldatopic-modelingtopicmodels

Why am I getting an error in 1:nrow(counts) : argument of length 0


I am doing topic modelling using the topicmodels package in R. I am creating a Corpus object, doing some basic preprocessing, and then creating a DocumentTermMatrix:

library(topicmodels)

#Set parameters for Gibbs sampling
burnin <- 4000
iter <- 2000
thin <- 500
seed <-list(2003,5,63,100001,765)
nstart <- 5
best <- TRUE

#Number of topics
k <- 8

#Run LDA using Gibbs sampling
# Start the clock!
ptm <- proc.time()
ldaOut <-LDA(dtm.new,k, method="Gibbs", control=list(nstart=nstart, seed = seed, best=best, 
                                                  burnin = burnin, iter = iter, thin=thin))
# Stop the clock
proc.time() - ptm

Then I got the error in the last line

 #docs to topics

ldaOut.topics <- as.matrix(topics(ldaOut))

Here is the error:

error in 1:nrow(counts) : argument of length 0

I assume that this means that it can't count the first row. Is there any way to check that.


Solution

  • Does topics() not already give you a matrix?

    In any case, "argument of length zero" is telling you that object "counts" has zero rows.