[R] Custom Command to Generate SQL
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Jun 19 07:21:53 CEST 2006
This generates the sql statement so just pass that to your database:
retrieve <- function(...) {
args <- list(...)
sub("and", "select * from people where",
paste(rbind("and", names(args), "=", dQuote(args)), collapse = " "))
}
# test
retrieve(firstname = "JOHN", middlename = "WILLIANS", lastname = "FORD")
On 6/19/06, Alex Restrepo <alex_restrepo at hotmail.com> wrote:
> Hi:
>
> I would like to create a custom command in R which generates SQL, which is
> then processed via RODBC.
>
> For example, the user would type:
>
> retrieve firstName('JOHN') middlleName('WILLIAMS') lastName('FORD')
>
> This would generate the following SQL which would then be processed by
> RODBC:
>
> Select *
> from people
> where firstName = 'JOHN' and
> middleName = 'WILLIAMS' and
> lastName = 'FORD'
>
> Does anyone have a recommendation? Any ideas would be greatly appreciated.
>
> Alex
>
> ______________________________________________
> 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