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

  • Home
  • SEARCH
  • 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 7434527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:51:12+00:00 2026-05-29T09:51:12+00:00

I have a comma-separated value file that looks like this when I open it

  • 0

I have a comma-separated value file that looks like this when I open it in vim:

12,31,50,,12^M34,23,45,2,12^M12,31,50,,12^M34,23,45,2,12^M

and so forth. I believe this means my CSV uses CR-only (classic mac) line endings. R’s read.table() function ostensibly requires LF line endings, or some variant thereof.

I know I can preprocess the file, and that’s probably what I’ll do.

That solution aside: is there a way to import CR files directly into R? For instance, write.table() has an “eol” parameter one can use to specify the line ending of outputs — but I don’t see a similar parameter for read.table() (cf. http://stat.ethz.ch/R-manual/R-patched/library/utils/html/read.table.html).

  • 1 1 Answer
  • 1 View
  • 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-05-29T09:51:12+00:00Added an answer on May 29, 2026 at 9:51 am

    R will not recognize “^M” as anything useful.(I suppose it’s possible that vim is just showing you a cntrl-M as that character.) If that were in a text-connection-stream R will think it’s not a valid escaped-character, since “^” is not used for that purpose. You might need to do the pre-processing, unless you want to pass it through scan() and substitute using gsub():

    subbed <- gsub("\\^M", "\n", scan(textConnection("12,31,50,,12^M34,23,45,2,12^M12,31,50,,12^M34,23,45,2,12^M"), what="character"))
    Read 1 item
    
    > read.table(text=subbed, sep=",")
      V1 V2 V3 V4 V5
    1 12 31 50 NA 12
    2 34 23 45  2 12
    3 12 31 50 NA 12
    4 34 23 45  2 12
    

    I suppose it’s possible that you may need to use “\\m” as the patt argument to gsub.

    A further note: The help page for scan says: “Whatever mode the connection is opened in, any of LF, CRLF or CR will be accepted as the EOL marker for a line and so will match sep = “\n”.” So the linefeed character (“\n”if that’s what they are) should have been recognized them, since read.table is based on scan. You should look at ?Quotes for information on escape characters.

    If this vim tutorial is to be believed those may be DOS-related characters since it offers this advice:

    Strip DOS ctrl-M’s:

    :1,$ s/{ctrl-V}{ctrl-M}//
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a comma separated CSV file looks like: customer1,customer2,,customer4, ,customer2,,customer4, custome1,,customer3,, I want
If I have a comma separated file like the following: foo,bar,n ,a,bc,d one,two,three ,a,bc,d
I have a method that reads data from a comma separated text file and
I have a file on disk that's only 168MB. It's just a comma separated
I have a CSV (comma separated values) file that contains student information. The column
I have a file that look like this: 1 543423 34354 2 5654656 3423
I have a field in my database that contain comma separated values these values
I have a comma separated list of strings like the one below. a,b ,c
I have a DB table that contains a comma separated list of ID's (ints)
I have a very simple function that takes a list of comma separated (x,y)

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.