Re: [R] Reference a variable inside a string and another for object assingments

2012-08-17 Thread Kenneth Rose
Thanks Gabor! This is exactly what I was searching for! --- And it works like a charm. On Fri, Aug 17, 2012 at 1:03 PM, Gabor Grothendieck wrote: > On Thu, Aug 16, 2012 at 3:30 PM, Kenneth Rose wrote: >> Hi R community >> >> I copied a bit of my R code that gets some data from a database. You

Re: [R] Reference a variable inside a string and another for object assingments

2012-08-17 Thread Kenneth Rose
I tried these two and testquery2 now does the job :) Somehow the str_c function from the stringr package doesn't work when I run the sqlQuery function even though the testquery string is the same as testquery2 string. Thanks for the pointers! fromdate <- c("'2005-01-01 00:00:00'") testquery <- st

Re: [R] Reference a variable inside a string and another for object assingments

2012-08-17 Thread Gabor Grothendieck
On Thu, Aug 16, 2012 at 3:30 PM, Kenneth Rose wrote: > Hi R community > > I copied a bit of my R code that gets some data from a database. You > won't be able to run the code, but I am a beginner so you will > probably understand what going on. > > I would like to make a variable I can refer to in

Re: [R] Reference a variable inside a string and another for object assingments

2012-08-16 Thread MacQueen, Don
I sometimes do this sort of thing with "tricks" like this: sql <- "select * from mytable where dt >= 'ADATE'" dbGetQuery( con, gsub('ADATE', '2012-06-12 23:14', sql) ) Or if mydates is a vector of dates stored as a POSIXt object: for (id in mydates) { dbGetQuery( con, gsub('ADATE', form

Re: [R] Reference a variable inside a string and another for object assingments

2012-08-16 Thread Greg Snow
Perhaps the sprintf function is what you are looking for. It is one way to insert information from a variable into a string. A couple of other options are paste, paste0, and the gsubfn package, but I think sprintf will be simplest for what you are asking. On Thu, Aug 16, 2012 at 1:30 PM, Kenneth

[R] Reference a variable inside a string and another for object assingments

2012-08-16 Thread Kenneth Rose
Hi R community I copied a bit of my R code that gets some data from a database. You won't be able to run the code, but I am a beginner so you will probably understand what going on. I would like to make a variable I can refer to inside the sqlQuery. Instead of writing the start date and time (ex