Submitted by: K Davis; Assigned to: Arun ; R-Forge link
I create a test package with the following setup
NAMESPACE:
import(data.table)
export("testFunction")
DESCRIPTION:
Package: testPackage
Type: Package
Title: What the package does (short line)
Version: 1.0
Date: 2014-03-31
Author: Who wrote it
Maintainer: Who to complain to <[email protected]>
Description: More about what it does (maybe more than one line)
License: GPL (>= 2)
Imports: data.table (>= 1.9.3)
R/testFunction.R:
testFunction <- function() {
dt <- data.table(customerId=c(1:10),categoryId=c(1:10),unitSales=c(1:10))
invisible(dcast.data.table(dt,customerId~categoryId,value.var="unitSales",fill=0L))
}
For the full package see the attached tar.gz. I build the package, install it, and then use it as follows:
# R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
# Platform: x86_64-pc-linux-gnu (64-bit)
library(testPackage)
testFunction()
# Error in do.call("CJ", list(1:10, 1:10)) : could not find function "CJ"
This is the bug. The function testFunction() can not find the data.table function CJ() despite the fact that data.table was imported.
However, if I have the package depend upon data.table, the problem goes away.
Looking at the sources for data.table 1.9.3 I see only one call of the form do.call(CJ...) it is in the file data.table.R in the function as.data.table.table() which provides some of the as() functionality for data.table and is registered with R through the setAs()
From this behaviour my guess is that functions registered through setAs() only have access to the globally available packages (The problem goes away when the import is replaced with a depends.). So, any functions registered through setAs() should not depend upon functions exported from data.table as these functions need not be available in the environment setAs() executed in.
So, my guess as to a solution would be to either re-implement the functionality of CJ() in the function as.data.table.table() or to find some other way of implementing as.data.table.table() that does not require a call to CJ().
Submitted by: K Davis; Assigned to: Arun ; R-Forge link
I create a test package with the following setup
NAMESPACE:
DESCRIPTION:
R/testFunction.R:
For the full package see the attached tar.gz. I build the package, install it, and then use it as follows:
This is the bug. The function
testFunction()can not find thedata.tablefunctionCJ()despite the fact thatdata.tablewas imported.However, if I have the package depend upon
data.table, the problem goes away.Looking at the sources for data.table 1.9.3 I see only one call of the form
do.call(CJ...)it is in the filedata.table.Rin the functionas.data.table.table()which provides some of theas()functionality fordata.tableand is registered with R through thesetAs()From this behaviour my guess is that functions registered through
setAs()only have access to the globally available packages (The problem goes away when the import is replaced with a depends.). So, any functions registered throughsetAs()should not depend upon functions exported from data.table as these functions need not be available in the environmentsetAs()executed in.So, my guess as to a solution would be to either re-implement the functionality of
CJ()in the functionas.data.table.table()or to find some other way of implementingas.data.table.table()that does not require a call toCJ().