Thanks a lot. The hint with readLines worked :)

Then I got it to work like this:
sql <- paste(readLines(con = "stmnt.sql"), collapse = " ")
result <- sqlQuery(db,sql)

Michel


2014-03-02 17:52 GMT+01:00 Gabor Grothendieck <ggrothendi...@gmail.com>:

> On Fri, Feb 28, 2014 at 5:16 AM, Streng Ge-heim <normann...@gmail.com>
> wrote:
> > Hi,
> >
> > first of all: I am new to R. Anyway, I would like to include sql files in
> > my r-script, which I load via source("scriptname") in the CLI.
> >
> > The sql files (i.e. "stmt.sql") contains select statements with joins,
> line
> > breaks, various characters, they can be quite long.
> >
> > My question is, is there a way to include external sql files for further
> > processing? Or how can I include them. I tried it with source(),
> read.table
> > but I could get it to work.
> >
>
> If the file a.sql contains an sql statement then this reads it into
> the R variable named sql:
>
>     sql <- readLines("a.sql")
>
> and that variable can be used as an input to a database statement in
> your R code.
>
> Alternately paste the contents of a.sql into your R code and surround
> it with single or double quotations marks depending on which
> is not used in your statement (or escape them with \ if they are both
> used).  (R can handle multi-line quoted strings.)
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to