Skip to content
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

[R-Forge #5519] dcast.data.table fails from within a package that imports data.table #31

Closed
arunsrinivasan opened this issue Jun 8, 2014 · 0 comments
Assignees
Labels
Milestone

Comments

@arunsrinivasan
Copy link
Member

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 <yourfault@somewhere.net>
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().

@arunsrinivasan arunsrinivasan added this to the v1.9.4 milestone Jun 19, 2014
@arunsrinivasan arunsrinivasan self-assigned this Jun 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant