Say we have already obtained text (.txt) files (either through webscraping or other means). We now want to upload these files into R. An easy way to do that is via the “readtext” package.
We will work with sample text data of Supreme Court of Canada cases. They are available under the DATASET tab. Please download them into a folder on your hard drive. You must ensure that the folder only contains the texts you want to import into R.
# Change the below folder path to the path of your target folder. Important: don't forget the little asterix *. It indicates that you want to import all files in that folder. Also make sure you only store the files you want to import in that folder.
folder <- "~/Google Drive/Teaching/Canada/Legal Data Science/2019/Data/Supreme Court Cases/*"
Now we can upload the texts from that target folder using the readtext() function.
scc_texts <- readtext(folder)
As you can see, the object is a dataframe that contains both the file name and its text.
In order to only work with the text use the $ operator which selects the text column.