0

During Personality insight analysis, the last code has not worked and error message "No encoding supplied: defaulting to UTF-8." was shown. I can not understand which point i should fix... Thank you very mush for your help.

#### FUNCTION TO TIDY UP THE PI RESPONSE TO TABLE FORMAT - some rough 
methods that can be improved below
tidyResponse <- function(data) 
{
  data <- as.data.frame(strsplit(as.character(data),"\"id\":\""))
  data <- data[-c(1:5), ] # remove dud first row
  data <- data.frame(matrix(data)) 
  data[,1]  <- gsub("\"","",data[,1] ) 
  data <- data.frame(do.call('rbind', 
  strsplit(as.character(data$matrix.data),',',fixed=TRUE)))
  data <- data[!grepl('name:',data$X5),]
  data <- data[!grepl('children:',data$X5),]
  data <- data[,-c(2,6), ] # remove columns we dont need - duplicates or 
  dont care for SAMPLING ERROR (now) but mght later
  rownames(data) <- NULL # resets row names to remove 'gaps'
  data$row <- as.numeric(rownames(data))
  return(data)
}

########## FUNCTION - ScreenScrape support Clean up Response from HTML to 
DOC.TXT (import speeches)
cleanDoc <- function(doc) 
{
  doc <- gsub("<.*?>", "", doc)
  doc <- gsub("\\t","",doc)
  doc <- gsub("\\n","",doc)
  doc <- gsub("\\r","",doc)
  doc <- gsub("\\t","",doc)
  doc <- gsub("\\n","",doc)
  doc <- gsub("\\r","",doc)
  doc <- gsub("&nbsp;","",doc)
  doc <- gsub("&quot;","",doc)
  return(doc)
}

getwd()
speeches <- read.csv("watson_data.csv",header=TRUE)
speeches <- data.frame(watson_data)
speeches
length <- dim(watson_data)[1]+0  # how long is our list?
for (i in 1:length) 



{
  doc <- watson_data
  doc <- cleanDoc(doc)
  response <- watson.personality_insights.analyze(doc)
  data <- content(response,style= "text") # here are the personality 
  insights!
  data <- tidyResponse(data)
  alldata <- rbind(alldata,data)
} # this part does not work, and shows the error message "No encoding 
supplied: defaulting to UTF-8."
  • This is not reproducible because you have not supplied definitions for objects like `watson_data` or defined many of those functions such as `watson.personality_insights.analyze()`. So it is difficult to say what is going on. – the-mad-statter Jul 23 '19 at 11:52
  • 3
    Even though this is not reproducible, I think that error is not an error but a message originating in `data <- content(response,style= "text")` under an assumption that this is `httr::content()`. If that is correct, I also don't think there is a `style` argument. To stop the message pass `encoding = "UTF-8"` like so: `data <- content(x = response, as = "text", encoding = "UTF-8")`. – the-mad-statter Jul 23 '19 at 12:01
  • Thank you for the helpful comments. Firstly, watson_data is my data set and sorry for "watson.personality_insight.analysis" I forgot putting the code... watson.personality_insights.analyze <- function(TEXT) { return(POST(url=pi_url, authenticate(username,password), add_headers("Content- Type"="text/plain","charset"="utf-8" ), body = TEXT )) } – Akari Tsukada Jul 23 '19 at 12:29
  • Thank you for your helpful reply. I could fix the error code, however in my code i still have a issue so that the result shows 0 rows. But, Thank you so much, I really appreciate to your help. – Akari Tsukada Jul 23 '19 at 12:41

0 Answers0