[R] RODBC sqlFetch

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Mon May 13 12:26:49 CEST 2002


You need to modify sqlFetch, which starts

"sqlFetch" <-
function (channel, sqtable, ..., colnames = FALSE, rownames = FALSE)
{
    if (channel < 0)
        stop("invalid channel")
    if (missing(sqtable))
        stop("Missing parameter")
    tablename <- as.character(substitute(sqtable))

replace that last line by tablename <- sqtable.

BDR


On Mon, 13 May 2002, juli g. pausas wrote:

> Richard and F. Tussell,
> Thank you very much for your explanations and suggestions.
>
> Richard, and any
> See my reply below.
>
>
>
> Richard Rowe ha escrito:
>
> > At 18:03 11/05/02 +0100, you wrote:
> > >Hi,
> > >Thanks for showing me how to use RODBC and odbcConnect.
> > >Now works nicely. The question I've got now is:
> > >
> > >noms <- list.files(pattern=".DBF")
> > ># removing extension names:
> > >noms <- sapply(noms, function(x) as.character(strsplit(x,".DBF")) ,
> > >USE.NAMES=F)
> > >
> > >for (i in 1:length(noms))  {
> > >        s <- sqlFetch(bdades, noms[i])
> > ># etc.
> > >}
> > >
> > >But it seems that sqlFetch() doesn't accept the name noms[i]. Neither
> > >paste(noms[1], sep = "").
> > >Any suggestion for workaround?
> >
> > Don't know but two suggestions
> >
> > 1) are the tables {noms} actually tables in the database which is linked
> > with the handle bdades?  If they are separate databases then they will
> > require separate DSN handles to link ...
>
> I think this is not needed. dbaseclima is the DSN for  a subdiretory (Panel
> control, ...), and after
> bdades <- odbcConnect("dbaseclima")
> I'm able to access to all tables in the subdirectory, without any problem.
> The problem is when I want to use the name of a table as an item of an array
> of names (noms[i], see below)
>
>
>
> > Solution: do some adjusting in the database so the various noms tables are
> > in the same database
> >
> > 2) the characters '[' and ']' seem to have special properties to pass
> > names, so noms[i] may not be being interpreted as the i-th member of
> > 'noms'  ... as I said earlier I don't know the detail of this construction
> >
> > Solution: name the table first
> >
> > >for (i in 1:length(noms))  {
> >
> >            nomfornow<-noms[i]  ## and you will need to ensure there are
> > quote marks around nomfornow
> >
> > >        s <- sqlFetch(bdades, nomfornow)
>
> I did try this option, but unfortunatly didn't work:
>
> >noms <- list.files(pattern=".DBF")
> ># removing extension names:
> >noms <- sapply(noms, function(x) as.character(strsplit(x,".DBF")) ,
> USE.NAMES=F)
> >
> > nom <- noms[1]
> > s <- sqlFetch(bdades, nom)
> Error in sqlFetch(bdades, nom) : nom :table not found on channel 0
> > nom
> [1] "R7031"
> > s <- sqlFetch(bdades, "R7031")  # this works perfectly
> >
>
>
> I got ca. 200 files I'd like to read, this is why I would like to use noms[i].
>
> cheers
>
> Juli
>
>
>
>
> > ># etc.
> > >}
> >
> > Richard Rowe
> > Senior Lecturer
> > Department of Zoology and Tropical Ecology, James Cook University
> > Townsville, Queensland 4811, Australia
> > fax (61)7 47 25 1570
> > phone (61)7 47 81 4851
> > e-mail: Richard.Rowe at jcu.edu.au
> > http://www.jcu.edu.au/school/tbiol/zoology/homepage.html
>
> --
> Juli G. Pausas
> Centro de Estudios Ambientales del Mediterraneo (CEAM)
> C/ C.R. Darwin 14, Parc Tecnologic,
> 46980 Paterna, Valencia, SPAIN
> Tel: (+ 34) 96 131 8227; Fax: (+ 34) 96 131 8190
> mailto:juli at ceam.es
> http://www.gva.es/ceam
>
> GCTE Fire Network - http://www.gva.es/ceam/FireNetwork
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list