AI helped me turn a BlueSky CSV file into an organized plan for cleaning data, counting words, measuring sentiment, and making an interactive chart. One useful lesson was that the instructions need to match the actual file. The first file I supplied was a retail survey with no written responses, so it could not support this assignment’s text analysis. The correct file contains 197 posts. This analysis uses the 144 posts tagged as English and explains why the other posts are left out. AI can save time writing code, but its choices about missing values, language, and duplicate records still need to be checked. The basic counts and sentiment totals were independently checked in Python. The R code still needs to be knitted in RStudio to confirm that the full report runs correctly.
The biggest weakness is that a dictionary counts words without fully understanding the message. For example, it treats “like” as positive even when a post uses it to mean “such as.” It also misses the approving tone of “Finally!” in one post because none of that post’s words match the dictionary. These examples show why a sentiment label should not be treated as a person’s actual opinion. Human judgment is needed to read posts in context, notice sarcasm, decide whether a post is really about shopping, and explain the limits of the sample. Mentions of the National Mall and transit malls make that especially important here. I would use these results to describe this collection of posts, rather than claim that they represent all shoppers or prove that people like malls.
My question is: What words appear often in these posts, and what sentiment labels does a simple English dictionary assign?
The source is the supplied file, my_post-2.csv. The
collection method and search terms were not supplied. This is a
description of the collected posts, not a random sample of BlueSky
users. No instructions inside a post are treated as instructions for
this analysis.
The code keeps posts with a usable post URI and text. It removes repeated copies of the same URI, but keeps identical text posted under different URIs. Those may be separate posts. Missing optional information, such as links or author names, does not cause a post to be removed.
Put this R Markdown file and the CSV in the same project folder. Install the packages listed in the accompanying instructions once, in the Console, before knitting.
if (!file.exists(params$data_file)) stop("Upload my_post-2.csv to the project folder.")
raw <- read_csv(params$data_file, col_types = cols(.default = col_character()),
na = c("", "NA"), show_col_types = FALSE)
required_columns <- c("uri", "text", "langs")
if (!all(required_columns %in% names(raw))) {
stop("The CSV must contain uri, text, and langs columns.")
}
posts_core <- raw %>%
mutate(source_row = row_number()) %>%
select(source_row, uri, text, langs) %>%
filter(!is.na(uri), str_trim(uri) != "",
!is.na(text), str_trim(text) != "")
# Repeated URIs should not contain conflicting versions of the text.
conflicts <- posts_core %>% group_by(uri) %>%
summarise(text_versions = n_distinct(text), .groups = "drop") %>%
filter(text_versions > 1)
if (nrow(conflicts) > 0) stop("Review repeated URIs with different text before continuing.")
posts_unique <- posts_core %>% distinct(uri, .keep_all = TRUE) %>%
mutate(language_group = case_when(
is.na(langs) | str_trim(langs) == "" ~ "Missing language tag",
str_detect(str_to_lower(langs), "(^|;\\s*)en(-[a-z]+)?\\s*(;|$)") ~ "English tag",
TRUE ~ "Other language tag"
))
language_counts <- posts_unique %>% count(language_group, name = "posts")
knitr::kable(language_counts, caption = "Language tags before filtering")
| language_group | posts |
|---|---|
| English tag | 144 |
| Missing language tag | 48 |
| Other language tag | 5 |
posts <- posts_unique %>% filter(language_group == "English tag") %>%
mutate(post_number = row_number())
if (nrow(posts) == 0) stop("No posts have an English language tag.")
audit <- tibble(
step = c("Imported", "Missing URI or text removed", "Repeated URIs removed",
"Missing or other language tags excluded", "English posts analyzed"),
posts = c(nrow(raw), nrow(raw) - nrow(posts_core),
nrow(posts_core) - nrow(posts_unique),
nrow(posts_unique) - nrow(posts), nrow(posts))
)
knitr::kable(audit, caption = "Cleaning counts")
| step | posts |
|---|---|
| Imported | 197 |
| Missing URI or text removed | 0 |
| Repeated URIs removed | 0 |
| Missing or other language tags excluded | 53 |
| English posts analyzed | 144 |
stopifnot(!anyDuplicated(posts$uri), all(!is.na(posts$text)))
There are 197 imported posts and 144 posts
in the English analysis. English tags include en
and regional variants such as en-US. A language tag is a
useful filter, but it does not prove that all words in a post are
English. Excluding missing tags can change the findings, so the results
apply only to the selected posts.
I remove web addresses beginning with http,
https, or www, and mentions beginning with
@. I replace literal newline markers, standardize
apostrophes, and convert text to lowercase. Short links without those
prefixes may remain. The original text stays in a separate column for
checking.
For a consistent rule, a word is a sequence of English letters with an optional apostrophe inside it. Numbers and emojis are not included. This simple rule can split hyphenated words and does not analyze emojis. It is a limitation of this analysis.
posts <- posts %>% mutate(clean_text = text %>%
str_replace_all(fixed("\\n"), " ") %>%
str_replace_all(fixed("\\r"), " ") %>%
str_replace_all("[’‘]", "'") %>%
str_replace_all("https?://\\S+|www\\.\\S+", " ") %>%
str_replace_all("(?<!\\S)@\\S+", " ") %>%
str_squish() %>% str_to_lower())
tokens <- posts %>% select(post_number, clean_text) %>%
mutate(word = str_extract_all(clean_text, "[a-z]+(?:'[a-z]+)?")) %>%
select(-clean_text) %>% unnest(word)
# Remove common words only for the word-frequency table.
# Keep the full tokens table for sentiment scoring.
word_counts <- tokens %>%
anti_join(tidytext::stop_words, by = "word") %>%
count(word, sort = TRUE) %>% arrange(desc(n), word)
knitr::kable(head(word_counts, 15),
col.names = c("Word", "Occurrences"),
caption = "Most common words after removing common stop words")
| Word | Occurrences |
|---|---|
| mall | 138 |
| national | 10 |
| shopping | 10 |
| time | 10 |
| people | 7 |
| store | 7 |
| strip | 7 |
| city | 6 |
| day | 6 |
| love | 6 |
| saturday | 6 |
| stores | 6 |
| america | 5 |
| dc | 5 |
| home | 5 |
if (nrow(word_counts) > 0) {
cat(sprintf('The most frequent remaining word is **%s**, with **%s occurrences**. ',
word_counts$word[1], word_counts$n[1]))
}
The most frequent remaining word is mall, with 138 occurrences.
cat('These are word occurrences, not counts of different people. A repeated word in one post counts more than once. Common words show what appears in the collection, but they do not explain why people mentioned it.')
These are word occurrences, not counts of different people. A repeated word in one post counts more than once. Common words show what appears in the collection, but they do not explain why people mentioned it.
I use the Bing dictionary available through tidytext. It
labels matching words positive or negative. A post’s score is its number
of positive word occurrences minus its number of negative word
occurrences. Repeated words count repeatedly.
“Balanced” and “No matched words” do not establish that a post is neutral. These labels describe dictionary matches, not a person’s true feelings. The method does not handle negation or sarcasm.
bing <- get_sentiments("bing")
matched_words <- tokens %>% inner_join(bing, by = "word")
post_matches <- matched_words %>% group_by(post_number) %>%
summarise(positive = sum(sentiment == "positive"),
negative = sum(sentiment == "negative"), .groups = "drop")
scored <- posts %>% left_join(post_matches, by = "post_number") %>%
mutate(positive = replace_na(positive, 0L),
negative = replace_na(negative, 0L),
matched = positive + negative,
score = positive - negative,
classification = case_when(
matched == 0 ~ "No matched words",
score > 0 ~ "Positive",
score < 0 ~ "Negative",
TRUE ~ "Balanced"
))
categories <- c("Positive", "Negative", "Balanced", "No matched words")
sentiment_summary <- scored %>% count(classification, name = "posts") %>%
complete(classification = categories, fill = list(posts = 0L)) %>%
mutate(percent = 100 * posts / nrow(scored),
classification = factor(classification, levels = categories)) %>%
arrange(classification)
knitr::kable(sentiment_summary, digits = 1,
col.names = c("Dictionary label", "Posts", "Percent of analyzed posts"))
| Dictionary label | Posts | Percent of analyzed posts |
|---|---|---|
| Positive | 52 | 36.1 |
| Negative | 32 | 22.2 |
| Balanced | 9 | 6.2 |
| No matched words | 51 | 35.4 |
coverage <- tibble(
measure = c("All word occurrences", "Matched word occurrences",
"Posts with at least one match", "Percent of posts with a match"),
value = c(nrow(tokens), nrow(matched_words), sum(scored$matched > 0),
round(100 * mean(scored$matched > 0), 1))
)
knitr::kable(coverage, caption = "How much of the text the dictionary covers")
| measure | value |
|---|---|
| All word occurrences | 3983.0 |
| Matched word occurrences | 222.0 |
| Posts with at least one match | 93.0 |
| Percent of posts with a match | 64.6 |
Hover over a bar to see the count and percentage. Every analyzed post appears in exactly one category, including posts without dictionary matches.
sentiment_summary <- sentiment_summary %>% mutate(
hover = paste0(classification, "<br>Posts: ", posts,
"<br>Percent: ", round(percent, 1), "%"))
plot_ly(sentiment_summary, x = ~classification, y = ~posts,
type = "bar", text = ~hover, hoverinfo = "text",
marker = list(color = c("#287D60", "#B64949", "#877445", "#687687"))) %>%
layout(title = "Dictionary sentiment labels for English-tagged posts",
xaxis = list(title = "Dictionary label",
categoryorder = "array", categoryarray = categories),
yaxis = list(title = "Number of posts", rangemode = "tozero", dtick = 10),
margin = list(b = 100), showlegend = FALSE)
The supplied file was independently checked in Python using the same cleaning rules and Bing dictionary. That check found 197 source posts, no repeated URIs, and no missing post text. It found 144 English-tagged posts, 48 posts without language tags, and five posts with other language tags. These are reference checks for this specific file, not expected results for every BlueSky dataset.
# These structural checks should hold even if the input is updated.
stopifnot(nrow(scored) == nrow(posts),
sum(sentiment_summary$posts) == nrow(posts),
sum(scored$positive) + sum(scored$negative) == nrow(matched_words),
abs(sum(sentiment_summary$percent) - 100) < 1e-8)
# Compare the current run with the independent check of the supplied CSV.
reference <- tibble(
measure = c("Imported posts", "English posts", "Word occurrences",
"Positive word matches", "Negative word matches",
"Positive posts", "Negative posts", "Balanced posts", "No-match posts"),
independently_checked = c(197, 144, 3983, 128, 94, 52, 32, 9, 51),
current_R_result = c(nrow(raw), nrow(posts), nrow(tokens),
sum(scored$positive), sum(scored$negative),
sum(scored$classification == "Positive"),
sum(scored$classification == "Negative"),
sum(scored$classification == "Balanced"),
sum(scored$classification == "No matched words"))
) %>% mutate(agrees = independently_checked == current_R_result)
knitr::kable(reference, caption = "Independent reference counts compared with this R run")
| measure | independently_checked | current_R_result | agrees |
|---|---|---|---|
| Imported posts | 197 | 197 | TRUE |
| English posts | 144 | 144 | TRUE |
| Word occurrences | 3983 | 3983 | TRUE |
| Positive word matches | 128 | 128 | TRUE |
| Negative word matches | 94 | 94 | TRUE |
| Positive posts | 52 | 52 | TRUE |
| Negative posts | 32 | 32 | TRUE |
| Balanced posts | 9 | 9 | TRUE |
| No-match posts | 51 | 51 | TRUE |
if (!all(reference$agrees)) {
warning("A reference count differs. Check the file, cleaning rules, and dictionary version.")
}
# Inspect scores for the first five analyzed posts without publishing usernames.
knitr::kable(scored %>% slice_head(n = 5) %>%
select(post_number, source_row, positive, negative, score, classification),
caption = "Five post-level spot checks")
| post_number | source_row | positive | negative | score | classification |
|---|---|---|---|---|---|
| 1 | 1 | 0 | 0 | 0 | No matched words |
| 2 | 2 | 1 | 0 | 1 | Positive |
| 3 | 3 | 2 | 0 | 2 | Positive |
| 4 | 4 | 0 | 1 | -1 | Negative |
| 5 | 5 | 2 | 3 | -1 | Negative |
knitr::kable(matched_words %>% filter(post_number <= 5) %>%
count(post_number, word, sentiment, name = "occurrences"),
caption = "The words behind those scores")
| post_number | word | sentiment | occurrences |
|---|---|---|---|
| 2 | like | positive | 1 |
| 3 | correctly | positive | 1 |
| 3 | right | positive | 1 |
| 4 | bored | negative | 1 |
| 5 | cool | positive | 1 |
| 5 | delayed | negative | 1 |
| 5 | hang | negative | 1 |
| 5 | love | positive | 1 |
| 5 | pretend | negative | 1 |
For a hand calculation, the second analyzed post has one positive match, “like,” and no negative matches. Its score is 1 - 0 = 1, so the method labels it positive. Reading the original post shows that “like” introduces an example of a transit station. It does not express liking. That is a concrete reason to question the label.
The fourth analyzed post has the negative match “bored” and no positive matches. Its score is 0 - 1 = -1. The fifth has two positive matches (“cool” and “love”) and three negative matches (“pretend,” “delayed,” and “hang”). Its score is 2 - 3 = -1. The full wording suggests sarcasm, which the dictionary itself cannot understand. These examples verify the arithmetic and also show why correct arithmetic does not guarantee a correct interpretation.
To finish the human review, read the original wording of the first five analyzed posts in RStudio. The chunk below makes a local review table without adding the full text to the published report. Record where you agree or disagree, and explain at least one disagreement in your discussion.
get_count <- function(label) sum(scored$classification == label)
cat(sprintf('Of the **%s** analyzed posts, **%s** received a positive dictionary label, **%s** a negative label, **%s** a balanced label, and **%s** had no matched words. ',
nrow(scored), get_count("Positive"), get_count("Negative"),
get_count("Balanced"), get_count("No matched words")))
Of the 144 analyzed posts, 52 received a positive dictionary label, 32 a negative label, 9 a balanced label, and 51 had no matched words.
cat(sprintf('The dictionary matched at least one word in **%.1f%%** of posts. ',
100 * mean(scored$matched > 0)))
The dictionary matched at least one word in 64.6% of posts.
cat('Positive labels occur more often than negative labels in this file, but that is not enough to conclude that people feel positive about shopping malls.')
Positive labels occur more often than negative labels in this file, but that is not enough to conclude that people feel positive about shopping malls.
The posts cover several meanings of “mall,” including shopping, public spaces, and transportation. A post can also express feelings about a flight, a store, or a memory rather than a mall itself. One pair of English-tagged posts has identical text under different URIs and remains in the data. Repeated messages and repeated authors can influence the counts. Before making a claim about shoppers, a person would need to check relevance, review uncertain sentiment labels, and understand how the posts were collected.
Original prompt, actual excerpt from the request: “create an rmarkdown file for data analysis”. The full request also asked for text and sentiment analysis, a plotly chart, verification, a two-paragraph reflection, and prompts and responses in plain English.
Actual first response, excerpt: “I’ll inspect the
spreadsheet, then create an R Markdown file with analysis, an
interactive chart, and a two-paragraph reflection in plain English.” The
assistant’s later inspection found that the original file was a
six-response survey without text data. I then supplied
my_post-2.csv as the replacement file.
Actual response after the replacement file, excerpt: “I’ll use this CSV for the R Markdown analysis, reflection, and interactive chart. I’ll first check its columns and text so the code matches your data.” The resulting report describes its language filter, word-counting rules, dictionary scores, verification checks, and limitations.
Suggested improved prompt to send for the assignment’s second substantive AI request:
Review my BlueSky_analysis.Rmd using my_post-2.csv. Check the R code that uses readr, dplyr, stringr, tidytext, and plotly. Verify the cleaning counts, confirm that missing optional metadata does not remove posts, and explain the English-language filter. Check that unmatched posts remain in the sentiment chart and that percentages use all analyzed posts. Hand-check the first five scores and identify one label that misreads the original wording. Return corrected R chunks if needed and explain the limitations in plain English. Do not invent results or say that code ran unless you actually ran it.
This suggested prompt has not yet been sent by the student. After sending it, save the actual reply and replace this note with a short account of what changed. Take screenshots of the real original and improved prompts and their replies for the discussion forum. A suggested prompt or a summary is not a screenshot of an actual exchange.
my_post-2.csv; collection details
were not provided.sessionInfo()
## R version 4.6.2 (2026-10-29)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.5 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
##
## locale:
## [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
## [4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
## [7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
## [10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
##
## time zone: UTC
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] plotly_4.12.1 ggplot2_4.0.3 tidytext_0.4.3 stringr_1.6.0 tidyr_1.3.2
## [6] dplyr_1.2.1 readr_2.2.0
##
## loaded via a namespace (and not attached):
## [1] janeaustenr_1.0.0 sass_0.4.10 generics_0.1.4
## [4] stringi_1.8.9 lattice_0.23-1 hms_1.1.4
## [7] digest_0.6.39 magrittr_2.0.5 evaluate_1.0.5
## [10] grid_4.6.2 RColorBrewer_1.1-3 fastmap_1.2.0
## [13] jsonlite_2.0.0 Matrix_1.7-6 httr_1.4.9
## [16] purrr_1.2.2 crosstalk_1.2.2 viridisLite_0.4.3
## [19] scales_1.4.0 jquerylib_0.1.4 cli_3.6.6
## [22] crayon_1.5.3 rlang_1.3.0 tokenizers_0.3.0
## [25] bit64_4.8.6 withr_3.0.3 cachem_1.1.0
## [28] yaml_2.3.12 otel_0.3.0 parallel_4.6.2
## [31] tools_4.6.2 tzdb_0.5.0 vctrs_0.7.3
## [34] R6_2.6.1 lifecycle_1.0.5 bit_4.6.0
## [37] htmlwidgets_1.6.4 vroom_1.7.1 pkgconfig_2.0.3
## [40] pillar_1.11.1 bslib_0.12.0 gtable_0.3.6
## [43] glue_1.8.1 data.table_1.18.6.1 Rcpp_1.1.2
## [46] xfun_0.62 tibble_3.3.1 tidyselect_1.2.1
## [49] rstudioapi_0.19.0 knitr_1.52 farver_2.1.2
## [52] htmltools_0.5.9 SnowballC_0.7.1 rmarkdown_2.32
## [55] compiler_4.6.2 S7_0.2.2