True, I'd actually misread the problem as being "' and not "".

In the interest of expediency, here's one solution I can think off the  
top of my head: using MS-Word (dunno if it's taboo in these lists, but  
it's what I have at hand at the moment–I believe in using all the  
tools available, if it will save time, which is most valuable):

First, make a copy of your data and test it, to make sure Word will  
preserve proper formatting (when you do "Save as," it gives you  
several options under formatting, from which to pick line breaks, etc.)

First, do Replace All "" --> " (Edit Menu --> Find --> Replace)
Then, depending on whether the rows begin with |" or | " (that is,  
pipe, double quotes; or pipe, space, double quotes), you can do either:
Replace All: |"^p --> |""^p
Replace All:  "^p -->  ""^p (note that the pipe has been replaced by a  
single whitespace)
^p stands for paragraph break in Word, so, it would essentially look  
for a single double quote followed by a Return, thereby ignoring  
single quotes that are followed by text.

I just tested this, and it worked like a charm.

Dennis: in theory, any text editor that supports regular expression  
should be able to do it. I'm fairly rusty on regex now (haven't used  
it in a while, I wish I could offer the exact command). Here are two  
free ones that do, if anyone wants to play around with regex:

www.barebones.com/products/textwrangler/textwranglerpower.html  
(Textwrangler, OS X)
sourceforge.net/apps/mediawiki/notepad-plus/index.php? 
title=Regular_Expressions (Notepad++, Windows)

Cheers, hope it helps,


Wil

On Sep 12, 2010, at 6:27 PM, Dennis Murphy wrote:

> Hi:
>
> On Sun, Sep 12, 2010 at 1:05 PM, Wil M Contreras Arbaje 
> <wil.contre...@gmail.com 
> > wrote:
> While you are looking for a solution within R, it might be simpler  
> to open your text file in almost any free text editor (Notepad++,  
> Textwrangler, Smultron, vim come to mind), and do Replace all "' for  
> ".
>
> There's one problem with that solution: if the character string at  
> the end of the line is blank (i.e., ""), then your suggestion will  
> leave one double quote at the end of a line. Not good. What is  
> needed is a gsub that takes two double quotes plus a wild card  
> character and replaces it with one double quote and a wild card  
> character. If you have an editor that can do that, let me  
> know...seriously. I suspect emacs can do this, but none of the basic  
> editors I know have that capability.
>
> Dennis
>
>
>
> On Sep 12, 2010, at 3:58 PM, jim holtman wrote:
>
> You can use the 'gsub' command to remove the quote marks.  You could
> readLines/writeLines the file to clean it up with gsub before using
> read.table on it so it can all be done within R.
>
> On Sun, Sep 12, 2010 at 1:58 PM, Eva Nordstrom <eva.nordst...@yahoo.com 
> > wrote:
> I am using read.table to import a text file within R.
>
> There are several "errors" in my text file.  An "extra" quotation  
> mark has
> inadvertently been included within a few text fields.
>
>
> e.g. for a pipe (|) delimited text file, I have something similar to  
> this:
>
> 1|7|30| "dog"
> 2|6|25| ""cat"
> 3|"4|20|""
> 4|5| 56| "mouse"
> 5|3|56| ""horse"
> 6|56| ""
>
> In the above example| there are extra quotation marks within the  
> fields for cat
> and horse. (row 2 and row 5)
>
> e.g. "cat , "horse
>
> One solution is to simply edit the text file and remove the extra  
> quotation
> mark.
>
> Is there a "good solution" I can implement form within R?
>
> I am OK with just importing the extra quotation marks and having nit  
> show up as
> part of the text field within R.
>
> e.g,
> "cat
> "horse
>
> Thanks.
>
>
>
>       [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
>
> -- 
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to