[R-SIG-Mac] RODBC
Marc Schwartz
marc_schwartz at me.com
Sat Mar 6 18:42:54 CET 2010
On Mar 6, 2010, at 11:17 AM, Ivan Calandra wrote:
> Dear Mac users,
>
> Up to now, I've run R on Windows and I have some problems using my scripts on Mac OS X 10.6, R.app GUI 1.31 (5537 Leopard build 64-bit).
>
> Here is the code I use to export a data.frame to an *.xls file:
> xlsFile <- odbcConnectExcel("test.xls", readOnly=F)
> sqlSave(xlsFile, test, tablename=test, rownames=F, addPK=T, append=F)
> odbcCloseAll()
>
> However, the function odbcConnectExcel() doesn't work on Mac.
>
> Could you help me transposing this code?
>
> I don't think some sample data would be necessary, but let me know if you would like to.
>
> Thanks in advance
> Regards,
> Ivan
odbcConnectExcel() is Windows only. The function is conditionally available when the package is installed based upon the OS or in the pre-built binaries.
Presuming that you have an ODBC driver installed for Excel on your Mac (either MS with an Office installation, or from Actual Technologies) and a DSN defined, you can use odbcConnect(). If you do not, then you cannot use an ODBC connection.
That being said, I am pretty sure that using ODBC you cannot create a new .XLS file, you can only read/write to/from an existing one, which includes appending new worksheets to an existing file.
You could use the WriteXLS package on CRAN to write one or more data frames to a new Excel file, where each data frame would be written to a new worksheet. The package requires Perl and Apple's default Perl installation is missing at least one required Perl package (Text::CSV_XS) which can be installed from the command line using CPAN. See the INSTALL file for the package here:
http://cran.r-project.org/web/packages/WriteXLS/index.html
HTH,
Marc Schwartz
More information about the R-SIG-Mac
mailing list