Reputation: 123
I'm having trouble with the data.table
package after installing a package from github using devtools
. My custom function (which uses data.table functionality) works when I load the function locally, however when I create a custom package on github and install the package from github, the function no longer works.
Load the required packages:
require(PerformanceAnalytics)
if(!require(PerformanceAnalytics)) install.packages("PerformanceAnalytics");
require(PerformanceAnalytics)
require(data.table)
if(!require(data.table)) install.packages("data.table"); require(data.table)
require(devtools)
if(!require(devtools)) install.packages("devtools"); require(devtools)
Create a dummy dataset:
data(edhec)
EDHEC<-data.frame(date=index(edhec),coredata(edhec))
EDHEC<-melt(EDHEC,id.vars="date")
EDHEC<-data.table(EDHEC,key=c("variable","date"))
Install my package from github using devtools:
install_github("r_jfreels","jfreels"); require(jfreels)
Run my function:
test_date(EDHEC)
This gives an error: "Error in min(date) : invalid 'type' (closure) of argument"
Now create the function locally:
test_date<-function(DF) {
DT<-data.table(date=DF$date,variable=DF$variable,value=DF$value,key=c('variable','value'))
DT[,list(start_date=min(date),end_date=max(date)),by=variable]
}
Test the function again:
test_date(EDHEC)
This works.
This is driving me nuts and I don't know what the problem is.
Upvotes: 4
Views: 667
Reputation: 49820
If you add Depends: data.table
to your DESCRIPTION file, it will "work". However, you should really put in the effort to pass R CMD check -- right now, it's nowhere close to passing.
Upvotes: 5