[R] Custom Command to Generate SQL

Alex Restrepo alex_restrepo at hotmail.com
Tue Jun 20 02:43:27 CEST 2006


Hi Gabor:

Thanks for the great example.  I am an R newbie, so please forgive my 
question, but
could you describe what the sub() function is doing in your example? Why is 
there an "and" in the first argument to the sub() function?


Many Thanks:

Alex


>From: "Gabor Grothendieck" <ggrothendieck at gmail.com>
>To: "Alex Restrepo" <alex_restrepo at hotmail.com>
>CC: r-help at stat.math.ethz.ch
>Subject: Re: [R] Custom Command to Generate SQL
>Date: Mon, 19 Jun 2006 01:21:53 -0400
>
>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