[rkward-devel] [rkward-cvs] SF.net SVN: rkward:[4063] trunk/rkward/rkward/plugins/00saveload/import

Stefan Rödiger stefan_roediger at gmx.de
Mon Dec 12 21:38:31 UTC 2011


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 at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rkward-devel




More information about the Rkward-devel mailing list