Re: [R] write.csv +RMySQL request

From: Tristan Casey <nub_vulcanis_at_hotmail.com>
Date: Sat, 01 Mar 2008 16:25:00 +1000

Finally cracked it! Thanks everyone for your unlimited patience.  

I had my code incorrect, the textConnection I was reading from had "" around it, when it should have just been the object. See below.  

>textConnection(b,open="r") - Not "b"!> zzz<-read.csv(y) > close(y)> zzz X x1 x2 x3 x41 1 1 4 5 72 2 2 3 6 7

> CC: r-help@r-project.org> From: cskiadas@gmail.com> Subject: Re: [R] write.csv +RMySQL request> Date: Fri, 29 Feb 2008 10:50:34 -0500> To: nub_vulcanis@hotmail.com> > The following worked for me (put together after reading ? > textConnection). Put simply, all read/write command work with > "connections", which are if you like "devices that know how to read > or write things". textConnection creates such a device that writes > (or reads if we used open="r") to/from an already existing vector.> If the file argument to write.csv is not a connection, then it is > interpreted as a file name, and a connection to read/write on that > file is automatically made for you. The description in ?write.csv > explains this part.> > x <- character()> y<-textConnection("x", open="w")> write.csv(iris,file=y)> close(y)> > Haris Skiadas> Department of Mathematics and Computer Science> Hanover College> > On Feb 29, 2008, at 4:37 AM, Tristan Casey wrote:> > > Well that is certainly good news if !

 write.csv output can be stored > > directly to a character vector!> >> > I have tried to specify a vector within the file="" argument for > > example;> >> > write.csv(a,file="b") where b is a preexisting character vector> >> > This does not work. Do I need to define b as something else, like a > > textConnection?> >> >> >> Date: Fri, 29 Feb 2008 09:16:11 +0000> >> From: ripley_at_stats.ox.ac.uk> >> To: nub_vulcanis_at_hotmail.com> >> CC: jholtman_at_gmail.com; r-help_at_r-project.org> >> Subject: RE: [R] write.csv +RMySQL request> >>> >> On Fri, 29 Feb 2008, Tristan Casey wrote:> >>> >>> Ahh, my apologies I must admit that I don't fully understand> >>> textConnections fully. I have been reading up on th RODBC package > >>> as an> >>> alternative to RMySQL.> >>>> >>> With the file argument in write.csv, are you saying it is > >>> possible to> >>> write the csv formated data directly to a cell in a MySQL > >>> database? I am> >>> unsure what the variable 'con' must consist of.> >>> >> No!
 , that it is possible to write it to an R character vector.> >>> >>> W
ould this need to be a character string that initially connects > >>> to the> >>> database (dbConnect) then pastes the MySQL query? I am unsure how to> >>> specify where the data is going with the file/connection argument.> >>>> >>> Thanks> >>>> >>>> >>>> Date: Fri, 29 Feb 2008 08:44:58 +0000> >>>> From: ripley_at_stats.ox.ac.uk> >>>> To: nub_vulcanis_at_hotmail.com> >>>> CC: jholtman_at_gmail.com; r-help_at_r-project.org> >>>> Subject: RE: [R] write.csv +RMySQL request> >>>>> >>>> On Fri, 29 Feb 2008, Tristan Casey wrote:> >>>>> >>>>> Thanks again for your help.> >>>>>> >>>>> I am wanting my variable to store a character string exactly as > >>>>> the write.csv function would store as a csv text file;> >>>>>> >>>>> IE: My goal is to store a data frame of this construction;> >>>>>> >>>>> x1 x2> >>>>> 1 2> >>>>> 3 4> >>>>>> >>>>> as "X1","X2",1,2,3,4 (the same format as CSV).> >>>>>> >>>>> I am aware of the file argument, however that is the problem, > >>>>> storing to> >>>>> a physical t!
 ext file and then importing into the SQL database > >>>>> is a very> >>>>> inefficient way of doing things, especially when I can use > >>>>> RMySQL to> >>>>> send commands directly to the database.> >>>>> >>>> You seem however unaware of text connections. Neither of us > >>>> said anything> >>>> about using a 'physical text file', and the documentation for> >>>> write.csv says> >>>>> >>>> file: either a character string naming a file or a > >>>> connection open> >>>> for writing. '""' indicates output to the console.> >>>>> >>>> A 'text connection; is not a file (physical or otherwise).> >>>>> >>>>> >>>>>> >>>>> Kind Regards,> >>>>>> >>>>> Tristan Casey BPsySci (UQ)> >>>>> + 4 Festa Court, Capalaba, QLD 4157> >>>>> H 8/33 Lilly St, Greenslopes, QLD 4120> >>>>> 0450 033 948> >>>>>> >>>>>> >>>>>> >>>>>> Date: Fri, 29 Feb 2008 05:12:04 +0000> >>>>>> From: ripley_at_stats.ox.ac.uk> >>>>>> To: jholtman_at_gmail.com> >>>>>> CC: nub_vulcanis_at_hotmail.com; r-help_at_r-project.org> >>>>>> Su!  bject: Re: [R] write.csv +RMySQL request> >>>>>>> >>>>>> On Thu, 28 Fe
b 2008, jim holtman wrote:> >>>>>>> >>>>>>> ?capture.output> >>>>>>>> >>>>>>> myoutput <- capture.output(write.csv(...))> >>>>>>> >>>>>> It would be better to write directly to a text connection: see > >>>>>> the 'file'> >>>>>> argument to write.csv.> >>>>>>> >>>>>>> On Thu, Feb 28, 2008 at 7:34 PM, Tristan Casey > >>>>>>> <nub_vulcanis_at_hotmail.com> wrote:> >>>>>>>> Hello,> >>>>>>>>> >>>>>>>> I am relatively new to R and learning its ins and outs. As > >>>>>>>> part of a website I am building, I need to read and write > >>>>>>>> csv files directly from an SQL database. Basically I want to > >>>>>>>> convert R variables (dataframes) into CSV format, store them > >>>>>>>> as another R variable (as a properly formatted text string > >>>>>>>> suitable for csv reading) and then send this to one row in a > >>>>>>>> database.> >>>>>>>>> >>>>>>>> The SQL part is fine, the problem arises because I cannot > >>>>>>>> capture the output of write.csv! It posts to the terminal > >>>>>>>> !
 when file="" is used, however I also want to store it. Does > >>>>>>>> anyone have any ideas?> >>>>>>>>> >>>>>>>> Thanks in advance!> >>>>>>> >>>>>> --> >>>>>> Brian D. Ripley, ripley@stats.ox.ac.uk> >>>>>> Professor of Applied Statistics, http://www.stats.ox.ac.uk/ > >>>>>> ~ripley/> >>>>>> University of Oxford, Tel: +44 1865 272861 (self)> >>>>>> 1 South Parks Road, +44 1865 272866 (PA)> >>>>>> Oxford OX1 3TG, UK Fax: +44 1865 272595> >>>>>> >>>>> _________________________________________________________________> >>>>> Your Future Starts Here. Dream it? Then be it! Find it at > >>>>> www.seek.com.au> >>>>> http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fninemsn%2Eseek% > >>>>> 2Ecom%2Eau%2F%3Ftracking%3Dsk%3Ahet%3Ask%3Anine%3A0%3Ahot% > >>>>> 3Atext&_t=764565661&_r=OCT07_endtext_Future&_m=EXT> >>>>> >>>> --> >>>> Brian D. Ripley, ripley@stats.ox.ac.uk> >>>> Professor of Applied Statistics, http://www.stats.ox.ac.uk/ > >>>> ~ripley/> >>>> University of Oxford, Tel: +44 186!
 5 272861 (self)> >>>> 1 South Parks Road, +44 1865 272866 (PA)> >>>> O
xford OX1 3TG, UK Fax: +44 1865 272595> >>>> >>> _________________________________________________________________> >>> Your Future Starts Here. Dream it? Then be it! Find it at > >>> www.seek.com.au> >>> http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fninemsn%2Eseek% > >>> 2Ecom%2Eau%2F%3Ftracking%3Dsk%3Ahet%3Ask%3Anine%3A0%3Ahot% > >>> 3Atext&_t=764565661&_r=OCT07_endtext_Future&_m=EXT> >>> >> -- > >> Brian D. Ripley, ripley@stats.ox.ac.uk> >> Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/> >> University of Oxford, Tel: +44 1865 272861 (self)> >> 1 South Parks Road, +44 1865 272866 (PA)> >> Oxford OX1 3TG, UK Fax: +44 1865 272595> >> > > 
_________________________________________________________________
Your Future Starts Here. Dream it? Then be it! Find it at www.seek.com.au

%2F%3Ftracking%3Dsk%3Ahet%3Ask%3Anine%3A0%3Ahot%3Atext&_t=764565661&_r=OCT07_endtext_Future&_m=EXT

        [[alternative HTML version deleted]]



R-help_at_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. Received on Sat 01 Mar 2008 - 06:29:49 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 01 Mar 2008 - 08:30:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive