Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting an environment from an R package

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.

like image 897
Sim Avatar asked Dec 22 '12 08:12

Sim


2 Answers

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 .

like image 122
G. Grothendieck Avatar answered Oct 25 '22 21:10

G. Grothendieck


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.

like image 28
Romain Francois Avatar answered Oct 25 '22 21:10

Romain Francois