-
Notifications
You must be signed in to change notification settings - Fork 969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[.data.table
requires import of other function to work when data.table is imported by package
#2341
Comments
Not sure if this addresses it, but the usual reference is the final question of the FAQ: https://stackoverflow.com/questions/10527072/using-data-table-package-inside-my-own-package/10529888#10529888 |
Possibly related to #2306? |
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) close #2341 |
One last remark: apparently the directions in the data.table::cedata comments (lines 17-21) also work. Adding
to my package also fixes the issue. Should this be part of the FAQ? |
Where and how exactly do you add this line? Adding this straightforwardly to NAMESPACE returns me
Adding this anywhere else does not work, only the |
@jangorecki is this part of the importing DT vignette? |
You need to include that line in a .R file, not NAMESPACE. I usually put it in the file that has my package documentation,
|
@MichaelChirico not, but could be. |
If needed in future, a repex f = function() data.table::as.data.table(iris)
g = function(x) x[1]
package.skeleton("pkg", list=c("f", "g"))
rm(f, g)
cat("Imports: data.table\n", file="pkg/DESCRIPTION", append=TRUE)
unlink("pkg/man", recursive=TRUE)
system("R CMD build pkg")
system("R CMD INSTALL pkg_1.0.tar.gz")
library(pkg)
x = f()
options(datatable.verbose=TRUE)
g(x)
#cedta decided 'pkg' wasn't data.table aware. Here is call stack with [[1L]] applied:
#[[1]]
#g
#
#[[2]]
#`[`
#
#[[3]]
#`[.data.table`
#
#[[4]]
#cedta
#
# Sepal.Length
# <num>
# 1: 5.1
# 2: 4.9
# 3: 4.7
# 4: 4.6
# 5: 5.0
# ---
#146: 6.7
#147: 6.3
#148: 6.5
#149: 6.2
#150: 5.9 |
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: