On Sunday 04 December 2011 20:44:42 Milan Bouchet-Valat wrote:
> Le dimanche 04 décembre 2011 à 20:24 +0100, Thomas Friedrichsmeier a
> 
> écrit :
> > well, for all I can see, all available solutions have some real
> > drawbacks. On my system, perl is no problem, while my rJava installation
> > tends to be broken, frequently. But certainly, for many users it will be
> > the other way around.
> 
> FWIW, the RODBC package can be used to read .xls and .xlsx files on
> Windows, since a driver is installed by default on that platform (as a
> bonus, Access .mdb and .mdbx files are also read). As it's written by
> Microsoft, we can expect it to support correctly these formats. ;-)
> 

Hi Milan,

sorry for the late reply! I'm still looking at all options and work on other 
thinks. But yes indeed this is an option too. It appears that on the long run 
we have to implement the "best" platform specific solution, which makes 
everything a bit more complicated, as suggested by Thomas. That's a pity IMHO.

> The code is relatively simple, and well documented (see [1], p. 16). For
> illustration purposes, here's what I'm using in a Rcmdr plugin I wrote
> (doItAndPrint() is Rcmdr way of running a command):
> 
> # 'file' contains the path to the file
> ext <- tolower(substring(file, nchar(file) - sop + 2, nchar(file)))
> channelStr <- switch(EXPR = ext,
>                    xls = "odbcConnectExcel",
>                    xlsx = "odbcConnectExcel2007",
>                    mdb = "odbcConnectAccess",
>                    accdb = "odbcConnectAccess2007")
> doItAndPrint(paste("channel <- ", channelStr, "(\"", file, "\")",
>                    sep=""))
> 
> # For Excel and Access, need to select a particular sheet or table
> tabdat <- sqlTables(channel)
> names(tabdat) <- tolower(names(tabdat))
> 
> if(ext == "mdb" || ext == "accdb")
>     tabdat <- tabdat[tabdat$table_type == "TABLE", 3]
> 
> if(ext == "xls" || ext == "xlsx") {
>     tabname <- tabdat$table_name
>     tabdat <- ifelse(tabdat$table_type == "TABLE",
>                      substring(tabname, 2, nchar(tabname) - 2),
>                      substring(tabname, 1, nchar(tabname) - 1))
> }
> 
> # If there are several tables
> if(length(tabdat) > 1)
>     fil <- tk_select.list(sort(tabdat),
>                           title=gettext_Rcmdr("Select one table"))
> else
>     fil <- tabdat
> 
> if(fil == "") {
>     Message(gettext_Rcmdr("No table selected"), type="error")
>     return()
> }
> 
> if(ext == "xls" || ext == "xlsx")
>     fil <- paste("[", fil, "$]", sep = "")
> 
> # Retrieve the data
> command <- paste("sqlQuery(channel=channel, select * from ", fil,")",
>                sep = "")
> doItAndPrint(paste("corpusDataset <- ", command, sep = ""))
> doItAndPrint("odbcCloseAll()")
> 
> 
> Just my two cents
> 
> 
> 1: http://cran.r-project.org/web/packages/RODBC/vignettes/RODBC.pdf
> 
> 

Thanks for sharing!

Regards
Stefan

> ---------------------------------------------------------------------------
> --- All the data continuously generated in your IT infrastructure
> contains a definitive record of customers, application performance,
> security threats, fraudulent activity, and more. Splunk takes this
> data and makes sense of it. IT sense. And common sense.
> http://p.sf.net/sfu/splunk-novd2d
> _______________________________________________
> RKWard-devel mailing list
> RKWard-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rkward-devel

------------------------------------------------------------------------------
Learn Windows Azure Live!  Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for 
developers. It will provide a great way to learn Windows Azure and what it 
provides. You can attend the event by watching it streamed LIVE online.  
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
RKWard-devel mailing list
RKWard-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rkward-devel

Reply via email to