[R] "\r" with RSQLite
Mikkel Grum
mi2kelgrum at yahoo.com
Thu Mar 16 05:30:48 CET 2006
Thanks for the tip. I've attempted the alternative
approach of using write.table, which allows you to see
the file and import it directly. Would the carriage
returns be visible with notepad or with the edit
command? Because I don't see the /r in the text file,
but still get it when I query the database:
> library(RSQLite)
Loading required package: DBI
> a <- (5:10)
> b <- (LETTERS[5:10])
> df <- as.data.frame(cbind(a, b))
> library(RSQLite)
> drv <- dbDriver("SQLite")
> con <- dbConnect(drv, dbname = "Test")
> write.table(df, file = "df.txt", quote = FALSE,
row.names = FALSE)
> dbWriteTable(con, "DF", "df.txt", header = TRUE,
row.names = FALSE, overwrite = TRUE)
[1] TRUE
> df2 <- dbGetQuery(con, "SELECT DISTINCT * FROM
DF")
> dbDisconnect(con)
[1] TRUE
> df2
a_b
1 5 E\r
2 6 F\r
3 7 G\r
4 8 H\r
5 9 I\r
6 10 J\r
Also, this time it doesn't recognise that I didn't
want the rownames. I've attempted to go throught the
source code, but can't trace the problem with the
carriage return.
Mikkel
--- bogdan romocea <br44114 at gmail.com> wrote:
> \r is a carriage return character which some editors
> may use as a line
> terminator when writing files. My guess is that
> RSQLite writes your
> data frame to a temp file using \r as a line
> terminator and then runs
> a script to have SQLite import the data (together
> with \r - this would
> be the problem), but I have no idea if that's really
> the case. Check
> the documentation or ask the maintainer.
>
>
> > -----Original Message-----
> > From: r-help-bounces at stat.math.ethz.ch
> > [mailto:r-help-bounces at stat.math.ethz.ch] On
> Behalf Of Mikkel Grum
> > Sent: Wednesday, March 15, 2006 1:46 PM
> > To: r-help at stat.math.ethz.ch
> > Cc: dj at research.bell-labs.com
> > Subject: [R] "\r" with RSQLite
> >
> > What am I doing wrong, or is the \r that I'm
> getting
> > in the example below a bug?
> >
> > > a <- (1:10)
> > > b <- (LETTERS[1:10])
> > > df <- as.data.frame(cbind(a, b))
> > >
> > > df
> > a b
> > 1 1 A
> > 2 2 B
> > 3 3 C
> > 4 4 D
> > 5 5 E
> > 6 6 F
> > 7 7 G
> > 8 8 H
> > 9 9 I
> > 10 10 J
> > > library(RSQLite)
> > > drv <- dbDriver("SQLite")
> > > con <- dbConnect(drv, dbname = "Test")
> > > dbWriteTable(con, "DF", df, row.names =
> FALSE,
> > overwrite = TRUE)
> > [1] TRUE
> > > df2 <- dbGetQuery(con, "SELECT DISTINCT *
> FROM
> > DF")
> > > dbDisconnect(con)
> > [1] TRUE
> > > df2
> > a b
> > 1 1 A\r
> > 2 2 B\r
> > 3 3 C\r
> > 4 4 D\r
> > 5 5 E\r
> > 6 6 F\r
> > 7 7 G\r
> > 8 8 H\r
> > 9 9 I\r
> > 10 10 J\r
> >
> > > sessionInfo()
> > R version 2.2.1, 2005-12-20, i386-pc-mingw32
> >
> > attached base packages:
> > [1] "methods" "stats" "graphics"
> "grDevices"
> > "utils" "datasets"
> > [7] "base"
> >
> > other attached packages:
> > RSQLite DBI
> > "0.4-1" "0.1-10"
> >
> >
> > Mikkel Grum
> > Genetic Diversity
> > International Plant Genetic Resources Institute
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
> >
>
More information about the R-help
mailing list