[R] RMySql inserts \r when using dbWriteTable

Albert Nigrin albert at goraltrading.com
Thu Nov 6 01:37:09 CET 2008


I am using R 2.8 and the latest versions of RMySQL on a Windows XP 64 bit
machine.
I was wondering if someone could help me figure out how to use dbWriteTable 
without inserting \r into my table.  Consider the following code snippet,
which is
run after I connect to my database.

myDFOut = dbReadTable(conn, "myDF")
print(myDFOut)
myDFIn = data.frame(x=paste("x", 1:5, sep = ""), y = paste("y", 1:5, sep =
""))
dbWriteTable(conn, name= "myDF", value = myDFIn, row.names=F, append =TRUE,
eol = "\r\n" )
myDFOut = dbReadTable(conn, "myDF")
print(myDFIn)
print(myDFOut)

I get the output:
> myDFOut = dbReadTable(conn, "myDF")
> print(myDFOut)
data frame with 0 columns and 0 rows
> myDFIn = data.frame(x=paste("x", 1:5, sep = ""), y = paste("y", 1:5, sep =
""))
> dbWriteTable(conn, name= "myDF", value = myDFIn, row.names=F, append
=TRUE, eol = "\r\n" )
[1] TRUE
> myDFOut = dbReadTable(conn, "myDF")
> print(myDFIn)
   x  y
1 x1 y1
2 x2 y2
3 x3 y3
4 x4 y4
5 x5 y5
> print(myDFOut)
   x    y
1 x1 y1\r
2 x2 y2\r
3 x3 y3\r
4 x4 y4\r
5 x5 y5\r

Is there any way not to insert the "\r" in the database?   I also get the
same output, if I change the eol argument to "\n" in dbWriteTable, as in the
following command.

dbWriteTable(conn, name= "myDF", value = myDFIn, row.names=F, append =TRUE,
eol = "\n" )

I have read previous discussion concerning SQLite, but I still can't figure
out what to do.

Thanks for your help.

Albert



More information about the R-help mailing list