R/convert_quanteda_to_slam.R

Defines functions convert_quanteda_to_slam

Documented in convert_quanteda_to_slam

#' A function to convert a quanteda dfm object to a slam::simple_triplet_matrix.
#'
#' @param quanteda_dfm A dfm object generated by the quanteda::dfm() function.
#' @export
convert_quanteda_to_slam <- function(quanteda_dfm){

    # convert to a topicmodels object, which is just some window dressing on a
    # slam::simple_triplet_matrix
    dtm <- quanteda::convert(quanteda_dfm, to = "topicmodels")

    # create a blank object to populate
    temp <- slam::simple_triplet_matrix(i = 1,
                                        j = 1,
                                        v = 1)

    # slot the information into the blank simple_triplet_matrix
    temp$i <- dtm$i
    temp$j <- dtm$j
    temp$v <- dtm$v
    temp$nrow <- dtm$nrow
    temp$ncol <- dtm$ncol
    temp$dimnames <- dtm$dimnames

    return(temp)

}
matthewjdenny/SpeedReader documentation built on March 25, 2020, 5:32 p.m.