# ============================================================================= # HSCI 841 Qualitative Research Methods and Analysis in Public Health - Lesson 1: # Foundations of Qualitative Data Analysis # Answer key for the in-lesson R activities # Data file(s): term projects/HSCI_841/transcripts/P01_Maya.txt (all 20 transcripts are in # HSCI_841_loneliness_data.zip; unzip it inside the course repository) # Packages: tidyverse, quanteda, tidytext (install once with the block below) # Reproduces every code block in the lesson. # # Paths are relative to the course repository root. Set your working directory there # (Session > Set Working Directory > Choose Directory, or open the course .Rproj) before running. # ============================================================================= # ==== Section 4: The Course R Toolchain / Install the course toolchain ==== # NOTE (answer key): the install block is commented out so the script can be sourced or run with # Rscript without reinstalling packages. Run it once, by hand, the first time you set the course up. # install.packages(c( # "tidyverse", # general data wrangling and plotting # "tidytext", # text-as-data verbs in the tidyverse idiom # "quanteda", # industrial-strength text analysis (later modules) # "quanteda.textstats", # keyness, readability, lexical diversity # "quanteda.textplots", # keyness plots, word clouds, network plots # "stringr", # text manipulation # "readtext", # reading text corpora into R # "igraph", # network analysis (a later module) # "topicmodels", # LDA topic modelling (a later module) # "irr" # intercoder reliability stats (a later module) # )) # Verify the install by loading the core stack library(tidyverse) library(quanteda) library(tidytext) # Smoke test: read one transcript into R # NOTE (answer key): the lesson page used "../term projects/...", which only works from inside # the modules/ folder. Every HSCI 841 path is now relative to the repository root. loneliness_dir <- "term projects/HSCI_841/transcripts" p01 <- readLines(file.path(loneliness_dir, "P01_Maya.txt")) length(p01) # number of lines head(p01, 12) # first 12 lines: metadata header # What success looks like: the object p01 exists, length(p01) is 65, and the first 12 lines are # the metadata header (Participant ID through Location). cat("Lines in P01_Maya.txt:", length(p01), "\n") cat("Header fields:", paste(sub(":.*$", "", head(p01, 11)), collapse = ", "), "\n") # The same check across the whole corpus: 20 transcripts, one file per participant. all_files <- list.files(loneliness_dir, pattern = "\\.txt$", full.names = TRUE) cat("Transcripts found:", length(all_files), "\n") cat("Participant turns in P01:", sum(grepl("^P:", p01)), " interviewer turns:", sum(grepl("^I:", p01)), "\n")