library(sentimentr) if (!require("pacman")) install.packages("pacman") pacman::p_load(sentimentr, dplyr, magrittr) library(readxl) library(magrittr) library(gofaster) library(termco) mydata2 <- read.table("covid_data_pull2.csv" ,header =TRUE , sep =",", stringsAsFactors =FALSE, fill = TRUE) x<-c('point of care ultrasound', 'mindray', 'zonare','B lines','Point of care ultrasound lung', 'excessive b-lines','excess b-lines', 'consolidation', 'diagnosis: Covid',' CoVid 19','SARS CoV' ,'coronavirus', 'air bronchogram', 'air bronchograms', 'atelectasis' , 'pleural thickening' , 'pleura thickened' ,'moth-eaten' ,'moth eaten' ,'irregular pleura', 'excess B lines','excessive B lines', 'flu like' ) y<-c(-1, -1, -1, -1,-1, -2,-2, -2, -2,-2, -2, -2, -2,-2,-2,-2,-2,-2,-2,-2,-2,-1,-1) key<-data.frame(x,y) mykey <-as_key(key) x1 <-c( 'a lines', 'normal', 'denies', 'without','excess', 'excessive', 'positive','negative', 'doubt','doubtful', 'unlikely', 'did not', 'low risk','no','not','none','absent','improbable','likely','more','many','probably', 'probable','repeated','multiple','some', 'possible','maybe' ,'perhaps','questionable','?' ,'nonetheless' ,'despite') y1 <-c( 4, 4, 1, 1, 2,2 ,2,1, 1, 1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,4,4,4,4) val_key<-data.frame(x1,y1) myvalkey<-as_key((val_key), comparison =mykey ,(sentiment=FALSE)) y <- (with(mydata2,sentiment_by(text.var = get_sentences(note_text),by = list(csn, name), polarity_dt=mykey, valence_shifters_dt =myvalkey ,n.before=6, n.after=6 , amplifier.weight = 3))) y2 <- (with(mydata2,sentiment(text.var = get_sentences(note_text),by = list(csn, name), polarity_dt=mykey, valence_shifters_dt =myvalkey ,n.before=6, n.after=6 , amplifier.weight = 3))) highlight(y, file = "polarity.html", open = TRUE, digits = 3, replace) write.csv(y2,'First_y_pocus_dataframe_pull2.csv')