I used readLines from gutenbergr to read my list of legal cases into R. The code looks like this:
my_list <- list.files(path = “C:UsersBen TiceDocumentsR StuffUW JobCasesdatatxts”, pattern = “.txt$”)
cases_lines <- lapply(my_list, readLines)
I can convert individual cases successfully like this:
df_convert <- data.frame(line=1:length(cases_lines[[1]]), text=cases_lines[[1]])
But I would like to be able to use data.frame on all 75 cases without having to convert each one separately.
I tried using the lapply function as well as for loops, but I cannot get either of them to work. For example, df_convert2 <- data.frame(line=1:length(cases_lines[[i]]), text=cases_lines[[i]]) runs but produces the following error message: “Error in cases_lines[[i]] : recursive indexing failed at level 2.”
Ultimately, I need a list of the cases as data frames, so I can iterate through them with stringr functions to look for character patterns.
Benjamin Tice is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.