1

I am developing a package containing a ReferenceClass that has a field of data.table class (defined in the data.table package):

MyRC <- setRefClass("MyRC", fields = list(myfield="data.table"))

When I write into package DESCRIPTION file:

Depends:
    data.table

everything is fine. However I heard that one should avoid using Depends whenever possible, so I rewrote it to:

Imports:
    data.table

This however throws an error when building the package:

# Error in refClassInformation(Class, contains, fields, methods, where) : 
#   class "data.table" for field 'myfield' is not defined

Am I really forced to use Depends in this case?

csgillespie
  • 59,189
  • 14
  • 150
  • 185
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75
  • 1
    Are you using roxygen for documentation. It should suffice to add a #' @import data.table in the reference class documentation. This will add the appropriate entry to the NAMESPACE. – jdharrison Jun 03 '14 at 18:41

1 Answers1

4

Include in your NAMESPACE file either

import(data.table)

to import the entire package, or import selectively

importClassesFrom(data.table, data.table)

to import just the data.table class definition. If importing selectively, it may be necessary to import other functions your package uses, e.g.,

importFrom(data.table, CJ)
Martin Morgan
  • 45,935
  • 7
  • 84
  • 112
  • This worked to build the package successfully. However, later I am calling a function in my package, which internally calls `CJ` function of `data.table`. This throws error that `CJ` is not defined, unless I explicitly call `require(data.table)` – Daniel Krizian Jun 03 '14 at 19:43
  • 1
    If you are importing selectively (`importClassesFrom...`) then you'll also need to selectively import other functions your package uses. I updated my answer; it should not be necessary to say `require(data.table)`. – Martin Morgan Jun 03 '14 at 19:49