Re: [R] Loading mdb

From: Kenn Konstabel <lebatsnok_at_gmail.com>
Date: Tue, 22 Mar 2011 21:09:25 +0000

I've used RODBC to read in ms access files... or if you're as lazy as me you could use the following below (it can handle some other ms office file types too and thinks it can recognize file types but as has been pointed out in this list, using it with excel probably means trouble)

read.mso <- function(fail, sheet="Sheet1$", browse=FALSE, tables=FALSE, FUN = NULL, ...){

    # require(RODBC)
    # require(utils)
    # 'fail' is Estonian for 'file', don't be confused :)
    whence <- strsplit(basename(fail), "\\.")[[1]][2]     if(is.null(FUN)) FUN <- switch(whence, xls=odbcConnectExcel,
                mdb=odbcConnectAccess, xlsx=odbcConnectExcel2007,
                accdb=odbcConnectAccess2007, dbf=odbcConnectDbase,
                identity)

    con <- FUN(fail)
    if(browse) browser()
    res <- if(tables) sqlTables(con) else sqlFetch(con, sheet, ...)     close(con)
    res
    }

# lists tables with TABLE=TRUE, otherwise sqlFetch'es the table named in "sheet"

On Tue, Mar 22, 2011 at 5:05 PM, LCOG1 <jroll_at_lcog.org> wrote:
>
> Well im thoroughly frustrated after 25 minutes of checking and rechecking my
> path.  What do i not know about loading a mdb that is keeping me from
> loading my data.
>
> i have loaded the Hmisc library and pointed it too my data using mdb.get and
> continue to get the following error.
>
> Error in system(paste("mdb-tables -1", file), intern = TRUE) :
>  'mdb-tables' not found
>
> Which i realize is saying that its not reading any tables within the mdb or
> not able to find any mdb at all at that location.
>
> the command i use is simply:
>
> RawInv.data..<-mdb.get('T:/Models/LandUse/GenericLandSupplyModel/Projects/2008BaseYear/EugeneUGB/Reporting/Summary.mdb')
>
> There is definitely a mdb in that location and the path is definitely
> correct.  Its an MS Access mdb with 4 tables.  When i open the said mdb i
> have to hit enter at a password window but no password is required.  Could
> this be hanging up R from reading it?  I have typically used dbf and csv or
> txt for import formats and am not real familiar with mdb but i realize how
> elementary this question is but i have spent 25 minutes now.  What am i
> missing.
>
> Thanks
>
> JR
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Loading-mdb-tp3397075p3397075.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_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.



R-help_at_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. Received on Tue 22 Mar 2011 - 21:15:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 Mar 2011 - 21:20:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive