Importing unstructured text data from a plain text file
In some cases, it could happen that your source text data has been stored in a plain text (.txt
) file. In this type of situation, if you want to do any kind of text analytics, you have to import plain text data into the R environment. In this recipe, you will import plain text data from a .txt
file and store it into an object of class text.
Getting ready
Suppose you have stored a text file containing a newspaper article or several abstracts related to a particular topic. In this example, you will use a text file that contains 10 abstracts retrieved from PubMed by doing a literature search with the keyword
term "Deep Learning"
. The filename is deapLearning.txt
.
How to do it…
Importing plain text data from a .txt
file is rather easy. It is like importing data from a CSV file. The only difference is that the resultant object will not be a data frame, rather it will be a vector of characters. Here is the single line of code to import text data...