6

I am developing an R package that wraps the rmongodb package and creates a developer-friendly interface for working with MongoDB. The package uses proto internally.

I'd like to export a single factory method via a proto object (an environment) called MongoDB, whose definition is:

MongoDB <- proto(
  new = function(., ...) {
    # Good stuff in here...
  }
)

During development with RStudio & devtools and during local testing this does not seem to be a problem. However, I am experiencing several problems:

  • devtools::check() insists on putting an import(MongoDB) in my NAMESPACE file which makes R CMD check fail with "Namespace dependency not required: 'MongoDB'".

  • When I remove this import directive, R CMD check fails with "object 'MongoDB' not found" while running my testthat tests, even if I manually add export(MongoDB). However, devtools::test() works fine in RStudio.

What is the recommended way of exporting proto objects, which are environments, from R packages?

Update:

Per Gabor's suggestion below, I've made sure that MongoDB.Rd declares MongoDB as data (the link has the source). I still get a failure in MongoDB not being visible in the tests (which use testthat). My DESCRIPTION file is here and NAMESPACE is here.

Sim
  • 13,147
  • 9
  • 66
  • 95
  • You may want to look at the [`RMongo`](http://cran.r-project.org/web/packages/RMongo/index.html) package as well .. it uses the Java driver and has a higher level interface than the `rmongodb` package. – Stennie Dec 22 '12 at 08:49

2 Answers2

3

Try this:

  1. Specify export("MongoDB") in your NAMESPACE file to make the MongoDB proto object publicly available.
  2. Specify LazyData: yes in your DESCRIPTION file so that it automatically loads when accessed.
  3. Add an .Rd file documenting it as a dataset.

It should then pass R CMD check .

G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341
  • Thanks for the suggestions, Gabor. I still fail `check` for the same reason: `MongoDB` cannot be found when loading the tests. I've updated the question with links to the `Rd` files, `DESCRIPTION` and `NAMESPACE`. – Sim Dec 23 '12 at 01:15
  • @Sim, I have created packages using the 3 points I mentioned and they worked so this is likely a problem with the development environment you are using and not R. You might need to take it up with the maintainer(s) of those tools. – G. Grothendieck Dec 23 '12 at 02:29
  • Just to make sure I understand: since the problem shows up with the tests, are you suggesting that I raise the issue with @hadley and see if it is about `testthat` (where the tests are) or `devtools` (which emits potentially wrong instructions in `NAMESPACE`)? – Sim Dec 23 '12 at 02:47
1

This directive :

import(MongoDB)

means that you import the MongoDB namespace into your package. Probably not what you want if i understand correctly.

I think you want to export the MongoDB object, then

export(MongoDB) 

should work fine.

Romain Francois
  • 17,432
  • 3
  • 51
  • 77
  • Right. The `import` statement is inserted by `devtools`, which is not cool. Alas, `export(MongoDB)` does not work. – Sim Dec 23 '12 at 00:30