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 6324391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:41:41+00:00 2026-05-24T16:41:41+00:00

I am having trouble to read a file containing lines like the one below

  • 0

I am having trouble to read a file containing lines like the one below in R.

"_:b5507F4C7x59005","Fabiana D\"atri"

Any idea? How can I make read.table understand that \” is the escape of quote?

Cheers,
Alexandre

  • 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-05-24T16:41:42+00:00Added an answer on May 24, 2026 at 4:41 pm

    It seems to me that read.table/read.csv cannot handle escaped quotes.

    …But I think I have an (ugly) work-around inspired by @nullglob;

    • First read the file WITHOUT a quote character.
      (This won’t handle embedded , as @Ben Bolker noted)
    • Then go though the string columns and remove the quotes:

    The test file looks like this (I added a non-string column for good measure):

    13,"foo","Fab D\"atri","bar"
    21,"foo2","Fab D\"atri2","bar2"
    

    And here is the code:

    # Generate test file
    writeLines(c("13,\"foo\",\"Fab D\\\"atri\",\"bar\"",
                 "21,\"foo2\",\"Fab D\\\"atri2\",\"bar2\"" ), "foo.txt")
    
    # Read ignoring quotes
    tbl <- read.table("foo.txt", as.is=TRUE, quote='', sep=',', header=FALSE, row.names=NULL)
    
    # Go through and cleanup    
    for (i in seq_len(NCOL(tbl))) {
        if (is.character(tbl[[i]])) {
            x <- tbl[[i]]
            x <- substr(x, 2, nchar(x)-1) # Remove surrounding quotes
            tbl[[i]] <- gsub('\\\\"', '"', x) # Unescape quotes
        }
    }
    

    The output is then correct:

    > tbl
      V1   V2          V3   V4
    1 13  foo  Fab D"atri  bar
    2 21 foo2 Fab D"atri2 bar2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble getting my program to read this XML file properly, it will
I'm having trouble reading a chunked response when using a StreamReader to read the
I am still having trouble understanding what interfaces are good for. I read a
I am having trouble with the window.onload and document.onload events. Everything I read tells
I'm having trouble determining the best way to read some input in for a
I have to read data from mdb-files using c++ but I'm having trouble getting
I'm having trouble with a Mac App Store submission. I'm using the method below
I am having trouble reading a text file to a list, what I have
I'm having trouble deserializing my XML file from a MemoryStream. I have a generated
I'm having trouble adding Mimetypes to MimetypesFileTypeMap. I've tried adding a META-INF/mime.types file just

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.