1

I am implementing a Comparison Cloud in power BI written in R Script but there seems to be an error that states

Error in as.data.frame.default(x[[i]], optional = TRUE) : 
  cannot coerce class '"function"' to a data.frame
Calls: data.frame -> as.data.frame -> as.data.frame.default

I've tried to run it in RStudio and it works perfectly.

#Subsection
  pol_subsections <- function(df) {
    x.pos <- subset(df$text, df$polarity > 0)
    x.neg <- subset(df$text, df$polarity < 0)
    x.pos <- paste(x.pos, collapse = " ")
    x.neg <- paste(x.neg, collapse = " ")
    all.terms <- c(x.pos, x.neg)
    return(all.terms)
  } 

all_tdm <- dataset %>%
    select( text = text.var, polarity = polarity) %>%
    pol_subsections() %>%
    VectorSource() %>%
    VCorpus() %>%
    TermDocumentMatrix(
        control = list(
            removePunctuation = TRUE,
            stopwords = stopwords(kind = "en")
        )
    ) %>%
    as.matrix() %>%
    set_colnames(c("positive", "negative"))

comparison.cloud(all_tdm, max.words = 40, colors = c("darkgreen", "darkred"))

This is my dataset:

head(dataset)
  my_data.all wc polarity pos.words neg.words   text.var
1         all  1        0         -         -       able
2         all  1        1  accurate         -   accurate
3         all  1        1 adaptable         -  adaptable
4         all  1        0         -         - additional
5         all  1        0         -         - applicable
6         all  1        1 available         -  available
  • hello and welcome. did you make sure R & package versions are identical between your rstudio and powerbi sessions? – Benjamin Schwetz May 10 '19 at 08:21
  • I have updated my packages in R. Also, RStudio and powerBI have the same R home directory. – Jared Dominic Caraan May 14 '19 at 10:11
  • did you double check, e.g. using session info https://stackoverflow.com/questions/11103189/how-to-find-out-which-package-version-is-loaded-in-r ? Also, your example is lacking some crucial information (e.g. loading packages) to be reproducible. so not much we can do... see here on how to make a better example: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Benjamin Schwetz May 14 '19 at 20:37

0 Answers0