2 Replies Latest reply on Jul 13, 2018 11:50 AM by Nathan Mannheimer

    sentiment score with R and Tableau

    Neeraj Khurana

      Hi All

       

      This is my first question so if I miss anything, please guide.

       

      I am new to R, has only done basic training. What I am trying to do is pass on string of words from my data to R, do a semi/inner join with the sentiment data and get the score. I have tested the following script in Rstudio and it works fine.

       

      beefdata<-readr::read_csv("data.csv")

      res<-dplyr::semi_join(tidytext::get_sentiments("afinn"),dplyr::mutate(readr::read_csv("data.csv"),word=as.character(word)),by=c('word'))

      View(res)

       

      In Tableau, I have got Rserve running and connected properly ( I have tested basic calc and they work fine on R). I am running following script in measure calc

       

      SCRIPT_STR("

      dplyr::left_join(

      data.frame(word=.arg1)

      ,tidytext::get_sentiments('afinn')

      ,by=c('word')

      ,sort=TRUE)$score"

      ,ATTR([word]))

       

      word is a dimension so I am passing it as ATTR([word]). When I drag word dimention from data source to viz and calc measure, I get following error

       

       

      • The result returned by the SCRIPT function is of an unexpected type.

       

       

      I am not sure if this is how it suppose to work. I am expecting a score where word found in the sentiment dictionary against my data set words.

       

      I have also enclosed the packaged workbook.