## Not run:
#
# docsText <- c(
# "Loved the food, service and atmosphere! We'll definitely be back.",
# "Very good food, reasonable prices, excellent service.",
# "It was a great restaurant.",
# "If steak is what you want, this is the place.",
# "The atmosphere is pretty bad but the food is quite good.",
# "The food is quite good but the atmosphere is pretty bad.",
# "I'm not sure I would come back to this restaurant.",
# "The food wasn't very good.",
# "While the food was good the service was a disappointment.",
# "I was very disappointed with both the service and my entree."
# )
# docsLanguage <- rep("en", length(docsText))
#
# tryCatch({
#
# # Perform sentiment analysis
# docsSentiment <- textaSentiment(
# documents = docsText, # Input sentences or documents
# languages = docsLanguage
# # "en"(English, default)|"es"(Spanish)|"fr"(French)|"pt"(Portuguese)
# )
#
# # Class and structure of docsSentiment
# class(docsSentiment)
# #> [1] "texta"
# str(docsSentiment, max.level = 1)
# #> List of 3
# #> $ results:'data.frame': 10 obs. of 2 variables:
# #> $ json : chr "{\"documents\":[{\"score\":0.9903013,\"id\":\"hDgKc\", __truncated__ }]}
# #> $ request:List of 7
# #> ..- attr(*, "class")= chr "request"
# #> - attr(*, "class")= chr "texta"
#
# # Print results
# docsSentiment
# #> texta [https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment]
# #>
# #> --------------------------------------
# #> text score
# #> ------------------------------ -------
# #> Loved the food, service and 0.9847
# #> atmosphere! We'll definitely
# #> be back.
# #>
# #> Very good food, reasonable 0.9831
# #> prices, excellent service.
# #>
# #> It was a great restaurant. 0.9306
# #>
# #> If steak is what you want, 0.8014
# #> this is the place.
# #>
# #> The atmosphere is pretty bad 0.4998
# #> but the food is quite good.
# #>
# #> The food is quite good but the 0.475
# #> atmosphere is pretty bad.
# #>
# #> I'm not sure I would come back 0.2857
# #> to this restaurant.
# #>
# #> The food wasn't very good. 0.1877
# #>
# #> While the food was good the 0.08727
# #> service was a disappointment.
# #>
# #> I was very disappointed with 0.01877
# #> both the service and my
# #> entree.
# #> --------------------------------------
#
# }, error = function(err) {
#
# # Print error
# geterrmessage()
#
# })
# ## End(Not run)
Run the code above in your browser using DataLab