Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8852089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:18:51+00:00 2026-06-14T13:18:51+00:00

I am running the following code with such error. > rat <- scan(sortedratings.csv,nlines=760,sep=,,what=rat.cols,multi.line=FALSE); Error

  • 0

I am running the following code with such error.

> rat <- scan("sortedratings.csv",nlines=760,sep=",",what=rat.cols,multi.line=FALSE);                                                       
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :                                                                         
  line 755 did not have 8 elements                                                                                                                    
>    

And here is the line that is causing all the trouble

ubuntu@ip-10-28-6-239:/data/csv$ sed -n "750,760p" sortedratings.csv                                                                                  
"281656475","2.5.0","Jul 17, 2011","","","KK9876",4,0                                                                                                 
"281656475","2.5.0","Jul 17, 2011","","","Lyteskin45",4,0                                                                                             
"281656475","2.5.0","Jul 17, 2011","","","Mrs. Felton",5,0                                                                                            
"281656475","2.5.0","Jul 17, 2011","","","Nick Bartoszek",4,0                                                                                         
"281656475","2.5.0","Jul 17,2011","","","SANFRANPSYCHO",5,0                                                                                          
"281656475","2.5.0","Jul 17, 2011","","","Wxcgfduytrewjgf@!?$(:@&amp;&amp;$&amp;@\"",5,0                                                              
"281656475","2.5.0","Jul 18, 2011","","","Downs58",5,0                                                                                                
"281656475","2.5.0","Jul 18, 2011","","","kitty1019",5,0                                                                                              
"281656475","2.5.0","Jul 18, 2011","","","Rj&amp;e",4,0                                                                                               
"281656475","2.5.0","Jul 18, 2011","","","Robin Kinzer",5,0                                                                                           
"281656475","2.5.0","Jul 18, 2011","","","Roderick Palmer",5,0                                                                                        
ubuntu@ip-10-28-6-239:/data/csv$ s

I have tried different fixes but i can’t figure out the correct one. Any idea?

i don’t have a problem removing the backslash for no text or anything.

Oh, forgot to add, the file is 1.4GB big, so i can’t read all the file or just replace it with sed, since it’s just too big for my system.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:18:53+00:00Added an answer on June 14, 2026 at 1:18 pm

    In the “Details” part of ?scan (used by read.table, read.csv and so on):

     If ‘sep’ is non-default, the fields may be quoted in the style of
     ‘.csv’ files where separators inside quotes (‘''’ or ‘""’) are
     ignored and quotes may be put inside strings by doubling them.
     However, if ‘sep = "\n"’ it is assumed by default that one wants
     to read entire lines verbatim.
    

    So it looks like your problem is the “escaped” quote \" in that line causing the trouble – R expects an escaped quote for a CSV to be a double quote "", not a backslashed quote \".

    I think your best bet here is to replace escaped quotes with double quotes, be it using Linux or in R (R example below):

    txt <- readLines("tmp.txt")
    txt <- gsub('\\\\"', '""', txt) # note the weird double backslashing because
                                    # `readLines` adds extra backslashes
    # if you `cat(txt, sep='\n')` you will see that the `\"` is now `""`
    

    Then you can use read.csv or scan like before (note the textConnection(txt) which converts the string into a file-like object for scan to use):

    read.csv(textConnection(txt), ...)
    

    Edit/Addition

    Re OP’s comment – the file is 1.4GB and there are difficulties reading it all into R at once, so how to do the sanitizing?

    Option 1

    You appear to be on Linux, so you could use sed:

    sed -ire 's!\\"!""!g' myfile.txt
    

    (Depending on where your data comes from, perhaps you could adjust the program that is outputting the data to output it in the format you require in the first place, but this is not always possible).

    Option 2

    If you are averse to using Linux or want an in-house R solution, use the n parameter to readLines to only read in a few lines at a time:

    # create the file object and open it, see ?file
    f <- file('tmp.txt')
    open(f)
    txt <- ''
    
    # now read in 100 lines at a time, say
    while (length(txt)) {
        txt <- readLines(f, n=100)
        # now do the sanitizing/coercing into a data frame, store.
        # ...
    }
    close(f)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Running the following code, I get a StackOverflowError at the getPackage() line. How can
I am getting the following error while running the code, Warning: require_once(product.php) [function.require-once]: failed
I am receiving the following error when running my code below /Users/Castillo/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/fileutils.rb:1423:in stat': No
I am running following code to create bmp image from pdf using Ghost4j i
I'm getting unexpected output when running following code, DateFormat df = new SimpleDateFormat(YYYY-MM-dd); Date
Running the following code, I get an exception: using (var client = new Pop3Client())
When running the following code I get no output but I cannot work out
I'm running the following code: new FileSystemXmlApplicationContext(/data/farm/Server/confData/1000004/contex.xml) and it throws java.io.FileNotFoundException: class path resource
When I tried running the following code product([1,2,3],['a','b']) it returned an object of the
I'm running the following code to get a random entry from a dictionary: SELECT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.