read

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

read

Val-17
Hi all,

I am trying to red data where single and double quotes are embedded
in some of the fields and prevented to read the data.   As an example
please see below.

vld<-read.table(text="name prof
  A      '4.5
  B       "3.2
  C       5.5 ",header=TRUE)

Error in read.table(text = "name prof \n  A      '4.5    \n  B
3.2     \n  C       5.5 ",  :
  incomplete final line found by readTableHeader on 'text'

Is there a way how to  read this data and gt the following output
  name prof
1    A  4.5
2    B  3.2
3    C  5.5

Thank you inadvertence

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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 | Threaded
Open this post in threaded view
|

Re: read

Mayooran
Hi you can save your data file in txt or csv file. Then you can use function " vld <-read.table("C:/Users/........ .txt",header=T)".

Regards
Mayooran

-----Original Message-----
From: R-help <[hidden email]> On Behalf Of Val
Sent: Friday, 9 August 2019 12:11 PM
To: [hidden email] ([hidden email]) <[hidden email]>
Subject: [R] read

Hi all,

I am trying to red data where single and double quotes are embedded
in some of the fields and prevented to read the data.   As an example
please see below.

vld<-read.table(text="name prof
  A      '4.5
  B       "3.2
  C       5.5 ",header=TRUE)

Error in read.table(text = "name prof \n  A      '4.5    \n  B
3.2     \n  C       5.5 ",  :
  incomplete final line found by readTableHeader on 'text'

Is there a way how to  read this data and gt the following output
  name prof
1    A  4.5
2    B  3.2
3    C  5.5

Thank you inadvertence

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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 | Threaded
Open this post in threaded view
|

Re: read

Bert Gunter-2
In reply to this post by Val-17
read.table() does not have a "text" argument, so maybe you need to go back
and go through a tutorial or two to learn R basics (e.g. about function
calls and function arguments ?)
See ?read.table  (of course)

Cheers,

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Aug 8, 2019 at 5:11 PM Val <[hidden email]> wrote:

> Hi all,
>
> I am trying to red data where single and double quotes are embedded
> in some of the fields and prevented to read the data.   As an example
> please see below.
>
> vld<-read.table(text="name prof
>   A      '4.5
>   B       "3.2
>   C       5.5 ",header=TRUE)
>
> Error in read.table(text = "name prof \n  A      '4.5    \n  B
> 3.2     \n  C       5.5 ",  :
>   incomplete final line found by readTableHeader on 'text'
>
> Is there a way how to  read this data and gt the following output
>   name prof
> 1    A  4.5
> 2    B  3.2
> 3    C  5.5
>
> Thank you inadvertence
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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 | Threaded
Open this post in threaded view
|

Re: read

Anaanthan
In reply to this post by Val-17
data <- read.table(header=TRUE, text='
 name prof
  A  4.5
  B  3.2
  C  5.5  
 ')

> On 9 Aug 2019, at 8:11 AM, Val <[hidden email]> wrote:
>
> Hi all,
>
> I am trying to red data where single and double quotes are embedded
> in some of the fields and prevented to read the data.   As an example
> please see below.
>
> vld<-read.table(text="name prof
>  A      '4.5
>  B       "3.2
>  C       5.5 ",header=TRUE)
>
> Error in read.table(text = "name prof \n  A      '4.5    \n  B
> 3.2     \n  C       5.5 ",  :
>  incomplete final line found by readTableHeader on 'text'
>
> Is there a way how to  read this data and gt the following output
>  name prof
> 1    A  4.5
> 2    B  3.2
> 3    C  5.5
>
> Thank you inadvertence
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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 | Threaded
Open this post in threaded view
|

Re: read

Val-17
Thank you  all, I can read the text file but the problem was there is
a single quote embedded  in  the first row of second column. This
quote causes the problem

vld<-read.table(text="name prof
  A      '4.5
  B       "3.2
  C       5.5 ",header=TRUE)

On Thu, Aug 8, 2019 at 7:24 PM Anaanthan Pillai
<[hidden email]> wrote:

>
> data <- read.table(header=TRUE, text='
>  name prof
>   A  4.5
>   B  3.2
>   C  5.5
>  ')
> > On 9 Aug 2019, at 8:11 AM, Val <[hidden email]> wrote:
> >
> > Hi all,
> >
> > I am trying to red data where single and double quotes are embedded
> > in some of the fields and prevented to read the data.   As an example
> > please see below.
> >
> > vld<-read.table(text="name prof
> >  A      '4.5
> >  B       "3.2
> >  C       5.5 ",header=TRUE)
> >
> > Error in read.table(text = "name prof \n  A      '4.5    \n  B
> > 3.2     \n  C       5.5 ",  :
> >  incomplete final line found by readTableHeader on 'text'
> >
> > Is there a way how to  read this data and gt the following output
> >  name prof
> > 1    A  4.5
> > 2    B  3.2
> > 3    C  5.5
> >
> > Thank you inadvertence
> >
> > ______________________________________________
> > [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> > 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.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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 | Threaded
Open this post in threaded view
|

Re: read

plangfelder
I would remove the quotes using sub, something like

# Read the file as text lines
text = readLines(con = file(yourFileName))
# Remove the offending quotes
text = gsub("'|\"", "", text)
# Concatenate and turn into a data frame
concat = paste(text, collapse = "\n")
df = read.table(text = concat, ...) # Change arguments as needed

HTH,

Peter

On Thu, Aug 8, 2019 at 5:41 PM Val <[hidden email]> wrote:

>
> Thank you  all, I can read the text file but the problem was there is
> a single quote embedded  in  the first row of second column. This
> quote causes the problem
>
> vld<-read.table(text="name prof
>   A      '4.5
>   B       "3.2
>   C       5.5 ",header=TRUE)
>
> On Thu, Aug 8, 2019 at 7:24 PM Anaanthan Pillai
> <[hidden email]> wrote:
> >
> > data <- read.table(header=TRUE, text='
> >  name prof
> >   A  4.5
> >   B  3.2
> >   C  5.5
> >  ')
> > > On 9 Aug 2019, at 8:11 AM, Val <[hidden email]> wrote:
> > >
> > > Hi all,
> > >
> > > I am trying to red data where single and double quotes are embedded
> > > in some of the fields and prevented to read the data.   As an example
> > > please see below.
> > >
> > > vld<-read.table(text="name prof
> > >  A      '4.5
> > >  B       "3.2
> > >  C       5.5 ",header=TRUE)
> > >
> > > Error in read.table(text = "name prof \n  A      '4.5    \n  B
> > > 3.2     \n  C       5.5 ",  :
> > >  incomplete final line found by readTableHeader on 'text'
> > >
> > > Is there a way how to  read this data and gt the following output
> > >  name prof
> > > 1    A  4.5
> > > 2    B  3.2
> > > 3    C  5.5
> > >
> > > Thank you inadvertence
> > >
> > > ______________________________________________
> > > [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> > > 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.
> >
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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 | Threaded
Open this post in threaded view
|

Re: read

Jeff Newmiller
In reply to this post by Bert Gunter-2
Val 1
Bert 0

On August 8, 2019 5:22:13 PM PDT, Bert Gunter <[hidden email]> wrote:

>read.table() does not have a "text" argument, so maybe you need to go
>back
>and go through a tutorial or two to learn R basics (e.g. about function
>calls and function arguments ?)
>See ?read.table  (of course)
>
>Cheers,
>
>Bert Gunter
>
>"The trouble with having an open mind is that people keep coming along
>and
>sticking things into it."
>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
>On Thu, Aug 8, 2019 at 5:11 PM Val <[hidden email]> wrote:
>
>> Hi all,
>>
>> I am trying to red data where single and double quotes are embedded
>> in some of the fields and prevented to read the data.   As an example
>> please see below.
>>
>> vld<-read.table(text="name prof
>>   A      '4.5
>>   B       "3.2
>>   C       5.5 ",header=TRUE)
>>
>> Error in read.table(text = "name prof \n  A      '4.5    \n  B
>> 3.2     \n  C       5.5 ",  :
>>   incomplete final line found by readTableHeader on 'text'
>>
>> Is there a way how to  read this data and gt the following output
>>   name prof
>> 1    A  4.5
>> 2    B  3.2
>> 3    C  5.5
>>
>> Thank you inadvertence
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> 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]]
>
>______________________________________________
>[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>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.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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 | Threaded
Open this post in threaded view
|

Re: read

Jeff Newmiller
In reply to this post by Val-17
Assuming your actual case is a file containing those characters, your example R string has to quote them. However, it seems like you want to disable interpreting quotes while you read this file.

vld<-read.table(text=
"name prof
  A      '4.5
  B       \"3.2
  C       5.5 "
,header=TRUE,quote="")

(The escape character isn't really there.)

On August 8, 2019 5:40:08 PM PDT, Val <[hidden email]> wrote:

>Thank you  all, I can read the text file but the problem was there is
>a single quote embedded  in  the first row of second column. This
>quote causes the problem
>
>vld<-read.table(text="name prof
>  A      '4.5
>  B       "3.2
>  C       5.5 ",header=TRUE)
>
>On Thu, Aug 8, 2019 at 7:24 PM Anaanthan Pillai
><[hidden email]> wrote:
>>
>> data <- read.table(header=TRUE, text='
>>  name prof
>>   A  4.5
>>   B  3.2
>>   C  5.5
>>  ')
>> > On 9 Aug 2019, at 8:11 AM, Val <[hidden email]> wrote:
>> >
>> > Hi all,
>> >
>> > I am trying to red data where single and double quotes are embedded
>> > in some of the fields and prevented to read the data.   As an
>example
>> > please see below.
>> >
>> > vld<-read.table(text="name prof
>> >  A      '4.5
>> >  B       "3.2
>> >  C       5.5 ",header=TRUE)
>> >
>> > Error in read.table(text = "name prof \n  A      '4.5    \n  B
>> > 3.2     \n  C       5.5 ",  :
>> >  incomplete final line found by readTableHeader on 'text'
>> >
>> > Is there a way how to  read this data and gt the following output
>> >  name prof
>> > 1    A  4.5
>> > 2    B  3.2
>> > 3    C  5.5
>> >
>> > Thank you inadvertence
>> >
>> > ______________________________________________
>> > [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> > 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.
>>
>
>______________________________________________
>[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>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.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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 | Threaded
Open this post in threaded view
|

Re: read

Bert Gunter-2
In reply to this post by Jeff Newmiller
I stand corrected!

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Aug 8, 2019 at 7:11 PM Jeff Newmiller <[hidden email]>
wrote:

> Val 1
> Bert 0
>
> On August 8, 2019 5:22:13 PM PDT, Bert Gunter <[hidden email]>
> wrote:
> >read.table() does not have a "text" argument, so maybe you need to go
> >back
> >and go through a tutorial or two to learn R basics (e.g. about function
> >calls and function arguments ?)
> >See ?read.table  (of course)
> >
> >Cheers,
> >
> >Bert Gunter
> >
> >"The trouble with having an open mind is that people keep coming along
> >and
> >sticking things into it."
> >-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >
> >
> >On Thu, Aug 8, 2019 at 5:11 PM Val <[hidden email]> wrote:
> >
> >> Hi all,
> >>
> >> I am trying to red data where single and double quotes are embedded
> >> in some of the fields and prevented to read the data.   As an example
> >> please see below.
> >>
> >> vld<-read.table(text="name prof
> >>   A      '4.5
> >>   B       "3.2
> >>   C       5.5 ",header=TRUE)
> >>
> >> Error in read.table(text = "name prof \n  A      '4.5    \n  B
> >> 3.2     \n  C       5.5 ",  :
> >>   incomplete final line found by readTableHeader on 'text'
> >>
> >> Is there a way how to  read this data and gt the following output
> >>   name prof
> >> 1    A  4.5
> >> 2    B  3.2
> >> 3    C  5.5
> >>
> >> Thank you inadvertence
> >>
> >> ______________________________________________
> >> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> >> 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]]
> >
> >______________________________________________
> >[hidden email] mailing list -- To UNSUBSCRIBE and more, see
> >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.
>
> --
> Sent from my phone. Please excuse my brevity.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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 | Threaded
Open this post in threaded view
|

Re: read

Val-17
Thank you Jeff! That was so easy command.

On Thu, Aug 8, 2019 at 11:06 PM Bert Gunter <[hidden email]> wrote:

>
> I stand corrected!
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Thu, Aug 8, 2019 at 7:11 PM Jeff Newmiller <[hidden email]> wrote:
>>
>> Val 1
>> Bert 0
>>
>> On August 8, 2019 5:22:13 PM PDT, Bert Gunter <[hidden email]> wrote:
>> >read.table() does not have a "text" argument, so maybe you need to go
>> >back
>> >and go through a tutorial or two to learn R basics (e.g. about function
>> >calls and function arguments ?)
>> >See ?read.table  (of course)
>> >
>> >Cheers,
>> >
>> >Bert Gunter
>> >
>> >"The trouble with having an open mind is that people keep coming along
>> >and
>> >sticking things into it."
>> >-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>> >
>> >
>> >On Thu, Aug 8, 2019 at 5:11 PM Val <[hidden email]> wrote:
>> >
>> >> Hi all,
>> >>
>> >> I am trying to red data where single and double quotes are embedded
>> >> in some of the fields and prevented to read the data.   As an example
>> >> please see below.
>> >>
>> >> vld<-read.table(text="name prof
>> >>   A      '4.5
>> >>   B       "3.2
>> >>   C       5.5 ",header=TRUE)
>> >>
>> >> Error in read.table(text = "name prof \n  A      '4.5    \n  B
>> >> 3.2     \n  C       5.5 ",  :
>> >>   incomplete final line found by readTableHeader on 'text'
>> >>
>> >> Is there a way how to  read this data and gt the following output
>> >>   name prof
>> >> 1    A  4.5
>> >> 2    B  3.2
>> >> 3    C  5.5
>> >>
>> >> Thank you inadvertence
>> >>
>> >> ______________________________________________
>> >> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> >> 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]]
>> >
>> >______________________________________________
>> >[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> >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.
>>
>> --
>> Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.