An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111108/8585b2aa/attachment.pl>
multi-line query
5 messages · jim holtman, Ben quant, Gabor Grothendieck
Why not just send it in as is. I use SQLite (via sqldf) and here is
the way I write my SQL statements:
inRange <- sqldf('
select t.*
, r.start
, r.end
from total t, commRange r
where t.comm = r.comm and
t.loc between r.start and r.end and
t.loc != t.new
')
On Tue, Nov 8, 2011 at 11:43 AM, Ben quant <ccquant at gmail.com> wrote:
Hello,
I'm using package RpgSQL. Is there a better way to create a multi-line
query/character string? I'm looking for less to type and readability.
This is not very readable for large queries:
s <- ?'create table r.BOD("id" int primary key,"name" varchar(12))'
I write a lot of code, so I'm looking to type less than this, but it is
more readable from and SQL standpoint:
s <- gsub("\n", "", 'create table r.BOD(
"id" int primary key
,"name" varchar(12))
')
How it is used:
dbSendUpdate(con, s)
Regards,
Ben
? ? ? ?[[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.
Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111108/3f76b472/attachment.pl>
On Tue, Nov 8, 2011 at 11:43 AM, Ben quant <ccquant at gmail.com> wrote:
Hello,
I'm using package RpgSQL. Is there a better way to create a multi-line
query/character string? I'm looking for less to type and readability.
This is not very readable for large queries:
s <- ?'create table r.BOD("id" int primary key,"name" varchar(12))'
I write a lot of code, so I'm looking to type less than this, but it is
more readable from and SQL standpoint:
s <- gsub("\n", "", 'create table r.BOD(
"id" int primary key
,"name" varchar(12))
')
How it is used:
dbSendUpdate(con, s)
The gsub is not needed: s <- "create table x ( a real, b integer )" dbSendUpdate(con, s)
Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
On Tue, Nov 8, 2011 at 1:04 PM, Ben quant <ccquant at gmail.com> wrote:
Because I don't know anything about sqldf. :) Here is what happens, but I"m sure it is happening because I didn't read the manual yet:
s <- sqldf('create table r.dat("id" int primary key,"val" int)')
Error in ls(envir = envir, all.names = private) : ?invalid 'envir' argument Error in !dbPreExists : invalid argument type
Assuming you have loaded RpgSQL and sqldf it works for me so there is likely some configuration in your setup, either with RpgSQL or with PostgreSQL itself.
s <- sqldf('create table dat("id" int primary key, "val" int)')
sqldf("select * from dat")
[1] id val <0 rows> (or 0-length row.names) If you are going to use your own create statements then you might be better off using RpgSQL directly rather than sqldf.
Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com