Quantcast

dbSendQuery with R variables

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

dbSendQuery with R variables

Jonathan Greenberg
Rhelpers:

I'd like to modify this RSQLite statement:

rs_stations<-dbSendQuery(con_stations, "select * from stations")

so that stations is actually an R variable, e.g.:

stations=c("stationA","stationB")

How would I modify the above statement to query from stations[[1]]
(aka "stationA")?

--j

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: dbSendQuery with R variables

jholtman
?paste

On Mon, May 10, 2010 at 6:21 PM, Jonathan Greenberg
<[hidden email]>wrote:

> Rhelpers:
>
> I'd like to modify this RSQLite statement:
>
> rs_stations<-dbSendQuery(con_stations, "select * from stations")
>
> so that stations is actually an R variable, e.g.:
>
> stations=c("stationA","stationB")
>
> How would I modify the above statement to query from stations[[1]]
> (aka "stationA")?
>
> --j
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



--
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: dbSendQuery with R variables

Seth Falcon-3
On 5/11/10 5:01 AM, jim holtman wrote:

> ?paste
>
> On Mon, May 10, 2010 at 6:21 PM, Jonathan Greenberg
> <[hidden email]>wrote:
>
>> Rhelpers:
>>
>> I'd like to modify this RSQLite statement:
>>
>> rs_stations<-dbSendQuery(con_stations, "select * from stations")
>>
>> so that stations is actually an R variable, e.g.:
>>
>> stations=c("stationA","stationB")
>>
>> How would I modify the above statement to query from stations[[1]]
>> (aka "stationA")?

In the end, I think paste is your only option.  The latest version of
RSQLite does support parameterized SELECT queries, but you cannot use
the parameters to specify table names, only values.

For details of what is supported, try reading through the examples in
help("dbSendPreparedQuery")


+ seth

--
Seth Falcon | @sfalcon | http://userprimary.net/

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: dbSendQuery with R variables

kman-4
In reply to this post by Jonathan Greenberg
?paste

See also,
http://rwiki.sciviews.org/doku.php?id=large_scale_data:lsdioi_sqchunk for
additional examples.

Assuming stations[1:2] are tables your database:
simpleQuery<- paste("SELECT * FROM", stations[1]) # should read the whole
table when invoked
dbGetQuery(con_stations, simpleQuery)

Is this sort of what you had in mind?

Sincerely,
KeithC.


-----Original Message-----
From: Jonathan Greenberg [mailto:[hidden email]]
Sent: Monday, May 10, 2010 4:21 PM
To: r-help
Subject: [R] dbSendQuery with R variables

Rhelpers:

I'd like to modify this RSQLite statement:

rs_stations<-dbSendQuery(con_stations, "select * from stations")

so that stations is actually an R variable, e.g.:

stations=c("stationA","stationB")

How would I modify the above statement to query from stations[[1]] (aka
"stationA")?

--j

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: dbSendQuery with R variables

Gabor Grothendieck
In reply to this post by Jonathan Greenberg
Try this.  If fn$ prefaces the function name, subject to certain rules
string which determine which arguments are re-interpreted,
interpolation somewhat like in perl occurs.  Here we have enclosed
stations[[1]] in back quotes.

library(gsubfn)
stations <- c("stationA", "stationB")
rs_stations <- fn$dbSendQuery(con_stations, "select * from `stations[[1]]`")

On Mon, May 10, 2010 at 6:21 PM, Jonathan Greenberg
<[hidden email]> wrote:

> Rhelpers:
>
> I'd like to modify this RSQLite statement:
>
> rs_stations<-dbSendQuery(con_stations, "select * from stations")
>
> so that stations is actually an R variable, e.g.:
>
> stations=c("stationA","stationB")
>
> How would I modify the above statement to query from stations[[1]]
> (aka "stationA")?
>
> --j
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Loading...