[Rodbcext-commits] r11 - in pkg: . geoclimate geoclimate/R geoclimate/inst geoclimate/man rodbcExt rodbcExt/R rodbcExt/man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jun 11 11:23:20 CEST 2011


Author: jaunario
Date: 2011-06-11 11:23:19 +0200 (Sat, 11 Jun 2011)
New Revision: 11

Added:
   pkg/geoclimate/
   pkg/geoclimate/DESCRIPTION
   pkg/geoclimate/NAMESPACE
   pkg/geoclimate/R/
   pkg/geoclimate/R/ascutils.R
   pkg/geoclimate/R/dataframeutils.R
   pkg/geoclimate/R/geoutils.r
   pkg/geoclimate/R/nasa.r
   pkg/geoclimate/R/sysutils.r
   pkg/geoclimate/inst/
   pkg/geoclimate/inst/geoclimate_skeleton.sql
   pkg/geoclimate/man/
   pkg/geoclimate/man/Ascii.Rd
Modified:
   pkg/rodbcExt/DESCRIPTION
   pkg/rodbcExt/R/closeExt.R
   pkg/rodbcExt/R/connectExt.R
   pkg/rodbcExt/R/getDrivers.R
   pkg/rodbcExt/man/closeExt.Rd
   pkg/rodbcExt/man/connectExt.Rd
   pkg/rodbcExt/man/getDrivers.Rd
Log:
added geoclimate package


Property changes on: pkg/geoclimate
___________________________________________________________________
Added: svn:ignore
   + temp


Added: pkg/geoclimate/DESCRIPTION
===================================================================
--- pkg/geoclimate/DESCRIPTION	                        (rev 0)
+++ pkg/geoclimate/DESCRIPTION	2011-06-11 09:23:19 UTC (rev 11)
@@ -0,0 +1,11 @@
+Package: geoclimate
+Type: Package
+Title: Climate and Weather Data Processing at the IRRI GIS Laboratory
+Version: 0.0.1
+Date: 2009-2-24
+Depends: methods, rodbcExt, weather
+Author: Jorrel Khalil S. Aunario
+Maintainer: <jaunario at gmail.com>
+Description: [description]
+License: GPL (>=2)
+LazyLoad: yes

Added: pkg/geoclimate/NAMESPACE
===================================================================
--- pkg/geoclimate/NAMESPACE	                        (rev 0)
+++ pkg/geoclimate/NAMESPACE	2011-06-11 09:23:19 UTC (rev 11)
@@ -0,0 +1 @@
+exportPattern("^[^\\.]")
\ No newline at end of file


Property changes on: pkg/geoclimate/R
___________________________________________________________________
Added: bugtraq:number
   + true

Added: pkg/geoclimate/R/ascutils.R
===================================================================
--- pkg/geoclimate/R/ascutils.R	                        (rev 0)
+++ pkg/geoclimate/R/ascutils.R	2011-06-11 09:23:19 UTC (rev 11)
@@ -0,0 +1,38 @@
+# Author: Jorrel Khalil S. Aunario, jaunario at gmail.com
+# Date :  30 April 2010
+# Version 0.0.1
+# Licence GPL v3
+
+fillMissing <- function(ascii, xllcorner,yllcorner,ncols,nrows,cellsize){
+    asclines <- readLines(ascii)
+    cols <- as.numeric(trim(sub("ncols","",asclines[1])))
+    rows <- as.numeric(trim(sub("nrows","",asclines[2])))
+    xll <- as.numeric(trim(sub("xllcorner","",asclines[3])))
+    yll <- as.numeric(trim(sub("yllcorner","",asclines[4])))
+    res<- as.numeric(trim(sub("cellsize","",asclines[5])))
+
+}
+
+asciiDataFrame <- function(ascfile, nodata.na=TRUE, verbose=FALSE){
+    asclines <- readLines(ascfile)
+    cols <- as.numeric(trim(sub("ncols","",asclines[grep("ncols", asclines)[1]])))
+    rows <- as.numeric(trim(sub("nrows","",asclines[grep("nrows", asclines)[1]])))
+    xll <- as.numeric(trim(sub("xllcorner","",asclines[grep("xllcorner", asclines)[1]])))
+    yll <- as.numeric(trim(sub("yllcorner","",asclines[grep("yllcorner", asclines)[1]])))
+    res<- as.numeric(trim(sub("cellsize","",asclines[grep("cellsize", asclines)[1]])))
+    nodata<- as.numeric(trim(sub("NODATA_value","",asclines[grep("NODATA_value", asclines)[1]])))
+    cell <- 1:(cols*rows)-1
+    nlayers <- length(asclines)/(rows+6)
+    dat <- numeric(0)
+    for (i in 1:nlayers){
+        #cat(1:(rows+6)+((rows+6)*(i-1)), "\n")
+        #flush.console()
+        dat <- cbind(dat,as.numeric(unlist(strsplit(asclines[1:rows+6+((rows+6)*(i-1))]," "))))
+    }
+    if(nodata.na){
+        dat[dat==nodata] <- NA
+    }
+    colnames(dat) <- 1:nlayers
+    dat <- as.data.frame(cbind(cell,dat),stringsAsFactors=FALSE)
+    return(dat)
+}

Added: pkg/geoclimate/R/dataframeutils.R
===================================================================
--- pkg/geoclimate/R/dataframeutils.R	                        (rev 0)
+++ pkg/geoclimate/R/dataframeutils.R	2011-06-11 09:23:19 UTC (rev 11)
@@ -0,0 +1,39 @@
+# Author: Jorrel Khalil S. Aunario, jaunario at gmail.com
+# Date :  30 April 2010
+# Version 0.0.1
+# Licence GPL v3
+
+cleanDframe <- function(dat, cols=colnames(dat), addcols=TRUE, rmOtherCols=TRUE){
+    miss <- cols[!cols %in% colnames(dat)]
+    if (addcols & length(miss)>0){
+        for (m in miss){
+            dat[,m] <- NA
+        }
+    } else if(!addcols & length(miss)>0){
+        return(FALSE)
+        stop("Missing Columns")
+    } 
+    dchk <- is.na(dat[,cols])
+    
+    if (nrow(dat)>0){
+        
+        if (length(cols)>1){
+            if(rmOtherCols){
+                dat <- dat[!rowSums(dchk)==length(cols),cols]
+            }else dat <- dat[!rowSums(dchk)==length(cols),]    
+        } else {
+            if(rmOtherCols){
+                dat <- dat[!dchk,cols]
+            }else dat <- dat[!dchk,]
+        }
+                
+    }    
+    return(dat)        
+}
+
+recodeMissing <- function(dat, cols, old, new=NA){
+    for (i in 1:length(cols)){
+        dat[dat[,cols[i]]==old,cols[i]] <- new
+    }
+    return(dat)
+}

Added: pkg/geoclimate/R/geoutils.r
===================================================================
--- pkg/geoclimate/R/geoutils.r	                        (rev 0)
+++ pkg/geoclimate/R/geoutils.r	2011-06-11 09:23:19 UTC (rev 11)
@@ -0,0 +1,78 @@
+# Author: Jorrel Khalil S. Aunario, jaunario at gmail.com
+# Date :  22 September 2010
+# Version 0.0.1
+# Licence GPL v3
+
+dd2DMS <- function(dd, lat=T){
+    if (dd!=-99){
+        aDD <- abs(dd)
+        deg <- trunc(aDD)
+        dec <- aDD - deg
+        mn <- round(dec*60)
+        DMS <- paste(deg, mn)
+        if (lat & dd>0){                                
+            DMS <- paste(DMS, "N")
+        } else if (lat & dd<0){
+            DMS <- paste(DMS, "S")
+        } else if (!lat & dd>0){
+            DMS <- paste(DMS, "E")
+        } else {
+            DMS <- paste(DMS, "W")
+        }
+    } else {
+        DMS <- "-99."
+    }
+    return(DMS)
+}
+
+dms2DD <- function(dms, deg="d",minute="'", sec='"'){
+    dms <- trim(dms)
+    directions <- substr(dms, nchar(dms), nchar(dms))
+    #d <- try(substr(dms,1,regexpr(deg,dms)-1),...) 
+    d <- try(as.numeric(trim(substr(dms,1,regexpr(deg,dms)-1))))
+    d[which(is.na(d))] <- as.numeric(trim(substr(dms[which(is.na(d))],1,nchar(dms[which(is.na(d))])-1)))
+    m <- try(as.numeric(trim(substr(dms,regexpr(deg,dms)+1,regexpr(minute,dms)-1))))
+    m[is.na(m)] <- 0 
+    s <- try(as.numeric(trim(substr(dms,regexpr(minute,dms)+1,regexpr(sec,dms)-1))))
+    s[is.na(s)] <- 0
+    md <- s/60
+    dd <- d+((m+md)/60)
+    dd[!directions %in% c("N","E")] <- -dd[!directions %in% c("N","E")]
+    #if (!directions %in% c("N","E")) dd <- -dd  
+    return(dd)
+}
+
+#dd2UTM <- function(lat,lon){
+#    
+#}
+
+getISO2 <- function(lat, lon,retries=5){
+    cnt <- 0
+    iso2fetch <- FALSE
+    svcurl <- paste("http://ws.geonames.org/countryCode?lat=",lat,"&lng=",lon,"&username=demo&style=full",sep="")
+    #if (is.na(countries1[i])) next
+    #if (countries1[i] != i2[167]) next
+    while((class(iso2fetch)=="try-error" | class(iso2fetch)=="logical") & cnt<retries){
+        cat(svcurl,"\n")
+        flush.console()
+        iso2fetch <- try(scan(svcurl, what='character', quiet=TRUE),silent=TRUE)
+        if (class(iso2fetch)=="try-error"){
+            cnt <- cnt+1
+            cat("Webservice failure on ",svcurl ,".\n Retries ", cnt,". (Will skip after 5th try) \n", sep="")
+            flush.console();
+        } else if (class(iso2fetch)=="character"){
+            if(length(iso2fetch)>1){
+                iso2fetch <- ""
+            } else {
+                if (nchar(iso2fetch)>1){
+                    cnt <- cnt+1
+                    cat("Webservice failure on ",svcurl ,".\n Retries ", cnt,". (Will skip after 5th try) \n", sep="")
+                    flush.console();
+                    iso2fetch <- FALSE
+                }
+            }
+        }   
+    }
+    if (cnt>=retries) iso2fetch <- NA
+    return(iso2fetch)         
+}

Added: pkg/geoclimate/R/nasa.r
===================================================================
--- pkg/geoclimate/R/nasa.r	                        (rev 0)
+++ pkg/geoclimate/R/nasa.r	2011-06-11 09:23:19 UTC (rev 11)
@@ -0,0 +1,81 @@
+# Author: Jorrel Khalil S. Aunario, jaunario at gmail.com
+# Date :  22 February 2011
+# Version 0.0.1
+# Licence GPL v3
+
+uploadNASA <- function(con, setname, cell, stdate="1983-1-1", enddate=Sys.Date(), update=TRUE, reupload=FALSE, savefile=FALSE, savedir=".", verbose=TRUE){
+    
+    success <- FALSE
+    
+    stdate <- as.Date(stdate)
+    enddate <- as.Date(enddate)
+    
+    fname <- paste("nasa_",cell,".txt", sep="")
+    
+    if (!update){
+        sqlQuery(con, paste("DELETE FROM",setname, "WHERE cell =",cell))
+        stdate <- as.Date("1983-1-1") 
+        reupload <- FALSE
+    } 
+            
+    if (fname %in% list.files(savedir,pattern="nasa.*.txt") & !reupload){
+        show.message(paste(cell, "done"), eol="\n")
+        success <- TRUE
+        return(success)
+    } else if(fname %in% list.files(savedir,pattern="nasa.*.txt") & reupload){
+        show.message(paste("Reading ", fname, sep=""), eol="\n")
+        dlines <- readLines(paste(savedir,fname,sep="/"))                
+    } else {
+        xy <- xyFromCell(raster(),cell)
+        if (verbose) show.message(paste("Downloading: Cell# ", cell," (",xy[1,"y"],",",xy[1,"x"], ")", sep=""), eol="\n")
+        dlines <- readURL(paste("http://earth-www.larc.nasa.gov/cgi-bin/cgiwrap/solar/agro.cgi?email=agroclim%40larc.nasa.gov&step=1&lat=",xy[1,"y"],"&lon=",xy[1,"x"],"&ms=",monthFromDate(stdate),"&ds=",dayFromDate(stdate),"&ys=",yearFromDate(stdate),"&me=",monthFromDate(enddate),"&de=",dayFromDate(enddate),"&ye=",yearFromDate(enddate),"&p=swv_dwn&p=T2M&p=T2MN&p=T2MX&p=RH2M&p=DFP2M&p=RAIN&p=WS10M&submit=Submit", sep=""), verbose=TRUE)
+    }
+    
+    #Check completeness of data
+    endline <- grep(paste(yearFromDate(enddate),format(doyFromDate(enddate),width=3)), dlines)
+    if(length(dlines)==0 | length(endline)==0){
+        if (verbose) show.message("Empty or Incomplete data.", eol="\n")
+        if (file.exists(paste(savedir,"/nasa_",cell,".txt",sep=""))) file.remove(paste(savedir,"/nasa_",cell,".txt",sep=""))        
+    } else {
+        if (savefile){
+            force.directories(savedir, recursive=TRUE)
+            writeLines(dlines, paste(savedir,"/nasa_",cell,".txt",sep=""))  
+        } 
+
+        hdr <- grep("YEAR DOY swv_dwn     T2M    T2MN    T2MX    RH2M   DFP2M    RAIN   WS10M", dlines)    
+
+        if (length(hdr)==0){
+            if (verbose) show.message("Unrecognized format.", eol="\n")
+            if (file.exists(paste(savedir,"/nasa_",cell,".txt",sep=""))) file.remove(paste(savedir,"/nasa_",cell,".txt",sep=""))
+        }
+
+        dlines <- dlines[(hdr+1):endline]
+        dvector <- unlist(strsplit(dlines, " "))
+        dvector <- dvector[dvector!=""]
+        dvector[dvector=="-"] <- NA
+        ddframe <- as.data.frame(matrix(as.numeric(dvector), ncol=10, byrow=TRUE))
+        colnames(ddframe) <- c("yr", "doy", "srad", "tavg", "tmin", "tmax", "rh2m", "tdew", "prec", "wind")
+        ddframe <- cleanDframe(ddframe, cols=colnames(ddframe)[-(1:2)], rmOtherCols=FALSE)
+        wdate <- as.character(dateFromDoy(ddframe$doy, ddframe$yr))
+        id <- 0
+        forupload <- cbind(id, cell, wdate, ddframe[,-(1:2)], stringsAsFactors=FALSE)
+        if (verbose) show.message(paste("Uploading Records #", nrow(forupload), sep=""), eol="\n")
+
+        try1 <- 1
+        repeat {
+            uploaded <- try(sqlSave(con, forupload, setname,rownames=FALSE, append=TRUE, fast=FALSE), silent=!verbose)
+            if (class(uploaded)!="try-error"){
+                success <- TRUE
+                break
+            } else if (try1 < 2){
+                con <- odbcReConnect(con)
+                try1 <- try1+1                
+            } else {
+                break
+            }
+        }
+        rm(dlines,dvector,ddframe,forupload)
+        gc(verbose=FALSE)
+    }           
+    return(success)    
+}

Added: pkg/geoclimate/R/sysutils.r
===================================================================
--- pkg/geoclimate/R/sysutils.r	                        (rev 0)
+++ pkg/geoclimate/R/sysutils.r	2011-06-11 09:23:19 UTC (rev 11)
@@ -0,0 +1,54 @@
+# Author: Jorrel Khalil S. Aunario, jaunario at gmail.com
+# Date :  22 February 2011
+# Version 0.0.1
+# Licence GPL v3
+
+show.message <- function(..., eol=NULL){
+    cat(...,eol,sep="")
+    flush.console()
+}
+
+openURL <- function(urlstr, retries=1, verbose=FALSE){
+    myurl <- url(urlstr)
+    tries <- 1
+    repeat{
+        if (verbose){
+            show.message(paste("Connecting to \n",urlstr, "(", retries, ")",sep=""), eol="\n")
+        }
+        try(open(myurl), silent=!verbose)
+        if (isOpen(myurl)){
+            break
+        } else if (tries>retries){
+            if(verbose) show.message("Connection Failed") 
+            break   
+        } else {
+            tries <- tries + 1
+        }    
+    }
+    return(myurl)
+}
+
+readURL <- function(urlstr, retries=1, verbose=FALSE){
+    lines <- character(0)
+    tries <- 1
+    repeat{
+        if (verbose){
+            show.message(paste("Connecting to \n",urlstr, "(", retries, ")",sep=""), eol="\n")
+        }
+        lines <- try(readLines(urlstr), silent=!verbose)
+        if (class(lines)=="try-error"){
+            tries <- tries + 1
+        } else {
+            break
+        }    
+    }
+    return(lines)    
+}
+
+force.directories <- function(path,...){
+    
+    if(!file.exists(path)){
+        success <- dir.create(path,...)  
+    } else success <- TRUE
+    return(success)
+}


Property changes on: pkg/geoclimate/inst
___________________________________________________________________
Added: bugtraq:number
   + true

Added: pkg/geoclimate/inst/geoclimate_skeleton.sql
===================================================================
--- pkg/geoclimate/inst/geoclimate_skeleton.sql	                        (rev 0)
+++ pkg/geoclimate/inst/geoclimate_skeleton.sql	2011-06-11 09:23:19 UTC (rev 11)
@@ -0,0 +1,61 @@
+DROP SCHEMA IF EXISTS `geoclimate` ;
+CREATE SCHEMA IF NOT EXISTS `geoclimate` DEFAULT CHARACTER SET utf8 COLLATE latin1_swedish_ci ;
+USE `geoclimate` ;
+
+-- -----------------------------------------------------
+-- Table `geoclimate`.`datasets`
+-- -----------------------------------------------------
+DROP TABLE IF EXISTS `geoclimate`.`datasets` ;
+
+CREATE  TABLE IF NOT EXISTS `geoclimate`.`datasets` (
+  `dataset_id` INT(11) NOT NULL AUTO_INCREMENT ,
+  `dataset_name` VARCHAR(45) NOT NULL ,
+  `table_name` VARCHAR(20) NOT NULL ,
+  `maskset_id` INT NOT NULL ,
+  `xmin` DECIMAL(8,4) NOT NULL ,
+  `xmax` DECIMAL(8,4) NOT NULL ,
+  `ymin` DECIMAL(8,4) NOT NULL ,
+  `ymax` DECIMAL(8,4) NOT NULL ,
+  `xres` DECIMAL(8,4) NOT NULL ,
+  `yres` DECIMAL(8,4) NOT NULL ,
+  `source` VARCHAR(100) NOT NULL ,
+  `remarks` TEXT NULL DEFAULT NULL ,
+  PRIMARY KEY (`dataset_id`) )
+ENGINE = MyISAM
+AUTO_INCREMENT = 2
+DEFAULT CHARACTER SET = utf8;
+
+
+-- -----------------------------------------------------
+-- Table `geoclimate`.`masksets`
+-- -----------------------------------------------------
+DROP TABLE IF EXISTS `geoclimate`.`masksets` ;
+
+CREATE  TABLE IF NOT EXISTS `geoclimate`.`masksets` (
+  `maskset_id` INT NOT NULL ,
+  `maskset_name` VARCHAR(15) NOT NULL ,
+  `maskset_desc` TEXT NULL ,
+  `xmin` FLOAT NOT NULL ,
+  `xmax` FLOAT NOT NULL ,
+  `xres` FLOAT NOT NULL ,
+  `ymin` FLOAT NOT NULL ,
+  `ymax` FLOAT NOT NULL ,
+  `yres` FLOAT NOT NULL ,
+  PRIMARY KEY (`maskset_id`) )
+ENGINE = MyISAM;
+
+
+-- -----------------------------------------------------
+-- Table `geoclimate`.`maskcells`
+-- -----------------------------------------------------
+DROP TABLE IF EXISTS `geoclimate`.`maskcells` ;
+
+CREATE  TABLE IF NOT EXISTS `geoclimate`.`maskcells` (
+  `maskset_id` INT NOT NULL ,
+  `cell` INT NOT NULL ,
+  `iso3` CHAR(3) NULL ,
+  `land` TINYINT(1)  NOT NULL DEFAULT FALSE ,
+  `arable` TINYINT(1)  NOT NULL DEFAULT FALSE )
+ENGINE = MyISAM;
+
+CREATE INDEX `mc_idx` ON `geoclimate`.`maskcells` (`maskset_id` ASC, `cell` ASC) ;


Property changes on: pkg/geoclimate/man
___________________________________________________________________
Added: bugtraq:number
   + true

Added: pkg/geoclimate/man/Ascii.Rd
===================================================================
--- pkg/geoclimate/man/Ascii.Rd	                        (rev 0)
+++ pkg/geoclimate/man/Ascii.Rd	2011-06-11 09:23:19 UTC (rev 11)
@@ -0,0 +1,35 @@
+\name{Ascii}
+\alias{fillMissing}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{ Closing Connections in rodbcExt }
+\description{
+  Closes a databases connection and then removes the object from memory. 
+}
+\usage{
+fillMissing()
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+}
+\details{
+  ~~ If necessary, more details than the description above ~~
+}
+\value{
+  ~Describe the value returned
+  If it is a LIST, use
+  \item{comp1 }{Description of 'comp1'}
+  \item{comp2 }{Description of 'comp2'}
+  ...
+}
+\references{ ~put references to the literature/web site here ~ }
+\author{ Jorrel Khalil S. Aunario }
+\note{ ~~further notes~~ 
+
+ %- ~~Make other sections like Warning with \section{Warning }{....} ~~
+}
+\seealso{ ~~objects to See Also as \code{\link{help}}, ~~~ }
+\examples{ # ~~ Create Examples Here ~~
+  }
+
+
+\keyword{ spatial }

Modified: pkg/rodbcExt/DESCRIPTION
===================================================================
--- pkg/rodbcExt/DESCRIPTION	2009-03-12 09:17:25 UTC (rev 10)
+++ pkg/rodbcExt/DESCRIPTION	2011-06-11 09:23:19 UTC (rev 11)
@@ -7,5 +7,5 @@
 Author: Jorrel Khalil S. Aunario
 Maintainer: <jaunario at gmail.com>
 Description: Enhanced database connectivity functions
-License: GPLv3
+License: GPL (>=2)
 LazyLoad: yes

Modified: pkg/rodbcExt/R/closeExt.R
===================================================================
--- pkg/rodbcExt/R/closeExt.R	2009-03-12 09:17:25 UTC (rev 10)
+++ pkg/rodbcExt/R/closeExt.R	2011-06-11 09:23:19 UTC (rev 11)
@@ -3,7 +3,7 @@
 # Version 0.1.1  
 # License GPL3
 
-disconnect <- function(channel, clean=T, env=.GlobalEnv){
+disconnect <- function(channel, clean=TRUE, env=.GlobalEnv){
     odbcClose(channel)
     if (clean){
         objs <- ls(envir=env)

Modified: pkg/rodbcExt/R/connectExt.R
===================================================================
--- pkg/rodbcExt/R/connectExt.R	2009-03-12 09:17:25 UTC (rev 10)
+++ pkg/rodbcExt/R/connectExt.R	2011-06-11 09:23:19 UTC (rev 11)
@@ -45,3 +45,25 @@
 		cat("Retrying to connect. (retries=",retries,") \n", sep="")
 	}
 }
+
+mysqlConnect <- function(driver=getMySQLDriver(), hostname="localhost",user="root", pwd="", database="",option=3, ...){
+    # check parameters 
+    info <- Sys.info()   
+    if(length(driver)==0){
+        stop("No MySQL Driver specified/found")
+    } else if(length(driver)>1){
+        driver <- driver[1]
+        warning("Only one driver is allowed. Using first in the vector.")
+    }
+    constring <- paste(
+        ifelse(info["sysname"]=="Windows",paste("DRIVER={",driver,"};",sep=""),paste("DRIVER=",driver,";",sep="")),
+        paste("SERVER=",hostname,";",sep=""), 
+        ifelse(database=="","",paste("DATABASE=",database,";",sep="")),
+        paste("USER=",user,";",sep=""),
+        paste("PASSWORD=",pwd,";",sep=""),        
+        paste("OPTION=",option,";",sep=""),
+        sep=""
+    )
+    return(odbcDriverConnect(constring,...))
+}
+

Modified: pkg/rodbcExt/R/getDrivers.R
===================================================================
--- pkg/rodbcExt/R/getDrivers.R	2009-03-12 09:17:25 UTC (rev 10)
+++ pkg/rodbcExt/R/getDrivers.R	2011-06-11 09:23:19 UTC (rev 11)
@@ -8,35 +8,30 @@
     if (info["sysname"]=="Windows"){
         iDrivers <- readRegistry("SOFTWARE\\ODBC\\ODBCINST.INI\\ODBC Drivers","HLM")
         driverList <- names(iDrivers)
-        return(driverList)
     }
-    else {
+    else if (info["sysname"]=="Linux"){
+        iDrivers <- system("odbcinst -q -d", intern=TRUE)
+        driverList <- sub("\\[", "",sub("\\]","",iDrivers))
+    } else {
         cat("Not yet supported. \n")
-        return(NULL)
+        driverList <- character(0)
     }
+    return(driverList)
 }
 
 getODBCDriver <- function(dbmsname){
-    info <- Sys.info()
-    if (info["sysname"]=="Windows"){
-        drivers <- getODBCDriverList()
-        avail <- grep(dbmsname, drivers)
+    drivers <- getODBCDriverList()
+    avail <- grep(dbmsname, drivers)
          
-        if (length(avail)>0){
-            # Return the first ODBC driver
-            return(drivers[avail[1]])
-        }
-        else {
-            return(NULL)
-        }
-        
+    if (length(avail)>0){
+        # Return the first ODBC driver
+        return(drivers[avail[1]])
     }
     else {
-        cat("Not yet supported. \n")
-        return(NULL)
+        return(character(0))
     }
 }
 
-getMySQLDriver <- function(){
+mysqlDriver <- function(){
     return(getODBCDriver("MySQL"))
 }

Modified: pkg/rodbcExt/man/closeExt.Rd
===================================================================
--- pkg/rodbcExt/man/closeExt.Rd	2009-03-12 09:17:25 UTC (rev 10)
+++ pkg/rodbcExt/man/closeExt.Rd	2011-06-11 09:23:19 UTC (rev 11)
@@ -28,10 +28,10 @@
 \author{ Jorrel Khalil S. Aunario }
 \note{ ~~further notes~~ 
 
- ~Make other sections like Warning with \section{Warning }{....} ~
+ %- ~~Make other sections like Warning with \section{Warning }{....} ~~
 }
 \seealso{ ~~objects to See Also as \code{\link{help}}, ~~~ }
-\examples{
+\examples{ # ~~ Create Examples Here ~~
   }
 
 

Modified: pkg/rodbcExt/man/connectExt.Rd
===================================================================
--- pkg/rodbcExt/man/connectExt.Rd	2009-03-12 09:17:25 UTC (rev 10)
+++ pkg/rodbcExt/man/connectExt.Rd	2011-06-11 09:23:19 UTC (rev 11)
@@ -38,10 +38,10 @@
 \author{ Jorrel Khalil S. Aunario }
 \note{ ~~further notes~~ 
 
- ~Make other sections like Warning with \section{Warning }{....} ~
+ %- ~~Make other sections like Warning with \section{Warning }{....} ~~
 }
 \seealso{ ~~objects to See Also as \code{\link{help}}, ~~~ }
-\examples{
+\examples{ # ~~ Create Examples Here ~~
   }
 
 

Modified: pkg/rodbcExt/man/getDrivers.Rd
===================================================================
--- pkg/rodbcExt/man/getDrivers.Rd	2009-03-12 09:17:25 UTC (rev 10)
+++ pkg/rodbcExt/man/getDrivers.Rd	2011-06-11 09:23:19 UTC (rev 11)
@@ -30,10 +30,10 @@
 \author{ Jorrel Khalil S. Aunario }
 \note{ ~~further notes~~ 
 
- ~Make other sections like Warning with \section{Warning }{....} ~
+ %- ~~Make other sections like Warning with \section{Warning }{....} ~~
 }
 \seealso{ ~~objects to See Also as \code{\link{help}}, ~~~ }
-\examples{
+\examples{ # ~~ Create Examples Here ~~
   }
 
 



More information about the Rodbcext-commits mailing list