Question

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?

Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top