title: Unable to read data correctly with read.table in R -- separate records are merged together. Trying to use gsub() to fix the file without success
body: <p>I am new in R and I am learning machine learning doing the Analytics Edge MIT course on EdX. There is an exercise in which we are called to read a dataset from here: <a href="http://files.grouplens.org/datasets/movielens/ml-100k/u.item" rel="nofollow noreferrer">http://files.grouplens.org/datasets/movielens/ml-100k/u.item</a></p>
  
  <p>These are ratings of movies from users.  I give you a sample of the data, although it is quite straightforward to view them on the Web:</p>
  
  <pre><code>    1|Toy Story (1995)|01-Jan-1995||http://us.imdb.com/M/title-exact?Toy%20Story%20(1995)|0|0|0|1|1|1|0|0|0|0|0|0|0|0|0|0|0|0|0 2|GoldenEye (1995)|01-Jan-1995||http://us.imdb.com/M/title-exact?GoldenEye%20(1995)|0|1|1|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0 3|Four Rooms (1995)|01-Jan-1995||http://us.imdb.com/M/title-exact?Four%20Rooms%20(1995)|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0 4|Get Shorty (1995)|01-Jan-1995||http://us.imdb.com/M/title-exact?Get%20Shorty%20(1995)|0|1|0|0|0|1|0|0|1|0|0|0|0|0|0|0|0|0|0
  </code></pre>
  
  <p>The data are to be copy-pasted into a text editor then saved as a txt file and then to be read with the following code:</p>
  
  <pre><code>    movies = read.table("movieLens.txt", header=FALSE, sep="|",quote="\"")
  </code></pre>
  
  <p>For testing purposes I have saved the above fragment in a text file -'test.txt'- and then tried to read it with the command:</p>
  
  <pre><code>    movies = read.table("test.txt", header=FALSE, sep="|",quote="\"")
  </code></pre>
  
  <p>When, I then run str() to inspect the file I am informed that all the records have been merged into one:</p>
  
  <pre><code>    str(movies)
      'data.frame':   1 obs. of  93 variables:
  </code></pre>
  
  <p>I experimented with the text and I observed that when I press carriage return after the end of each record the text is read correctly using the following code:</p>
  
  <pre><code>d = read.table("test.txt", 
                 header=FALSE, sep="|",quote="\"",
                 col.names=c("ID", "Title", "ReleaseDate", "VideoReleaseDate", "IMDB", "Unknown", "Action", "Adventure", "Animation", "Childrens", "Comedy", "Crime", "Documentary", "Drama", "Fantasy", "FilmNoir", "Horror", "Musical", "Mystery", "Romance", "SciFi", "Thriller", "War", "Western"), 
                 fill=FALSE, 
                 strip.white=TRUE)
  </code></pre>
  
  <p>So then I thought to use gsub() to enter \n after the end of each record.</p>
  
  <p>Here I run into new troubles as I can not find a way to substitute the grouped part of the pattern.</p>
  
  <p>So for example,</p>
  
  <pre><code>notables &lt;- c("  Ben Franklin and Jefferson Davis")
  gsub('n(\\s)F', '\n', notables)
  </code></pre>
  
  <p>returns:</p>
  
  <pre><code>[1] "  Be\nranklin and Jefferson Davis"
  </code></pre>
  
  <p>I would expect to return instead: "  Ben\nFranklin and Jefferson Davis", i.e. replace only the grouped part of the pattern and not the entire pattern.</p>
  
  <p>So here are two issues:</p>
  
  <ol>
  <li>How to read the file given the problems I described?</li>
  <li>How to correct my code so that gsub() replaces only the grouped part of the regex pattern?</li>
  </ol>