nassimhddd
nassimhddd

Reputation: 8510

Writing an R package depending on differing packages per architecture

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 ?

Upvotes: 1

Views: 85

Answers (1)

Henrik
Henrik

Reputation: 14450

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.

Upvotes: 1

Related Questions