1

I want to build a package that involves loading data from mysql using different packages depending on the user's system.

For a windows user it would be through an ODBC connection via package RODBC, while a linux/mac user would use the RMySQL package.

In a script, the following works very well:

if(.Platform$OS.type == "unix") {
library(RMySQL)
} else {
  library(RODBC)
}

Now I would like to have these packages loaded at the loading of my package. I would normally add it in the DESCRIPTION file, under 'Depends:', but this doesn't allow the optional clause.

What is the best way to handle this ?

nassimhddd
  • 8,340
  • 1
  • 29
  • 44

1 Answers1

1

I think the usual way to solve this is via the .onLoad function (see ?.onLoad or help(".onLoad")).

Section 1.6.3 of the Writing R Extension Manuals gives an overview. Perhaps someone else can point you to a good example, I haven't used it so far.

Henrik
  • 14,202
  • 10
  • 68
  • 91
  • Thanks! This is my first package and I must confess I didn't read the Writing R Extension Manuals so far. – nassimhddd Jul 04 '12 at 09:40
  • @cafe876 Then you should do so. At least the chapters that appear relevant to what you want to do based on the table of contents. – Henrik Jul 04 '12 at 09:58