Session Ready
Exercise

Reading a text file

It can be very useful to quickly import ordinary text files into R if, for example, you want to perform some kind of text mining analysis. readr offers two ways of doing so.

The first way is to use read_lines(). This function returns a vector of character strings. Each item in the vector represents one line in the original file.

The second way is to use read_file(), which returns a length 1 vector of the entire file, with line breaks represented as \n.

In this exercise, you'll be working with a collection of tweets from @RealCarrotFacts on Twitter.

Instructions
100 XP
  • Import tweets.txt using read_lines(). Call the resulting character vector tweets.
  • Import tweets.txt using read_file(). Call the resulting string tweets_all.