[R] write.csv +RMySQL request
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Feb 29 09:44:58 CET 2008
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 text 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
>> Subject: Re: [R] write.csv +RMySQL request
>>
>> On Thu, 28 Feb 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 at 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 at 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
More information about the R-help
mailing list