When writing packages, I generally declare an Imports dependency in the DESCRIPTION then use fully qualified names when invoking the package functions, e.g. data.table::fread().
However, this method fails to import the S3 methods into a namespace that my package can use. Specifically, [ fails and falls back to the [.data.frame unless I explicitly import at least one function from the data.table package in my NAMESPACE. While I can add importFrom(data.table, ...), it seems a bit of a hack to me.
Is this a data.table specific issue, or a general failing in R that requires with regard to S3 methods in package namespaces?
The text was updated successfully, but these errors were encountered:
The final FAQ covers it but is an ugly hack in my opinion. I should not have to pollute my package's namespace.
As I said in the original post, , importing a single symbol from the data.table package fixes the problem. I guess that's because the import() and importFrom() in the NAMESPACE generally do the same thing, with importFrom() having an additional final operation (filtering symbols).
For now I'll live with importFrom(data.table,data.table)
You need to include that line in a .R file, not NAMESPACE. I usually put it in the file that has my package documentation, @importFrom statements etc. For example:
# Import package operators
#' @importFrom magrittr "%>%" "%<>%"
#' @importFrom data.table ":=" "%like%" "%between%"
# Make sure data.table knows we know we're using it
.datatable.aware = TRUE
# Prevent R CMD check from complaining about the use of pipe expressions
# standard data.table variables
if (getRversion() >= "2.15.1")
utils::globalVariables(c(".", ".I", ".N", ".SD"), utils::packageName())