Bug 15038 - Error using Imports with a package that uses [
Summary: Error using Imports with a package that uses [
Status: NEW
Alias: None
Product: R
Classification: Unclassified
Component: Low-level (show other bugs)
Version: R 2.15.1
Hardware: x86_64/x64/amd64 (64-bit) Mac OS X v10.8
: P5 normal
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2012-08-31 07:35 UTC by Doug Mitarotonda
Modified: 2012-09-03 22:46 UTC (History)
0 users

See Also:


Attachments
Package that helps demonstrate bug (2.96 KB, application/zip)
2012-08-31 07:35 UTC, Doug Mitarotonda
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Doug Mitarotonda 2012-08-31 07:35:52 UTC
Created attachment 1369 [details]
Package that helps demonstrate bug

I receive an error when I create my own package that Imports the lubridage package because of from what I can tell a bug with the "[" function being used in lubridate. 

Prior discussion on this bug can be found here:
https://github.com/hadley/lubridate/issues/127

I have attached a stripped down package that replicates the error. After building the package, the error can be created by running the following code:

> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
> version
               _                            
platform       x86_64-apple-darwin9.8.0     
arch           x86_64                       
os             darwin9.8.0                  
system         x86_64, darwin9.8.0          
status                                      
major          2                            
minor          15.1                         
year           2012                         
month          06                           
day            22                           
svn rev        59600                        
language       R                            
version.string R version 2.15.1 (2012-06-22)
nickname       Roasted Marshmallows         
> options(error = recover)
> library(lubridate.sample)
> lubridate.sample:::main
function(){
	force_tz(Sys.time())
}
<environment: namespace:lubridate.sample>
> lubridate.sample:::main()
Error in hour(with_tz(new, tzone)) : could not find function "hour"

Enter a frame number, or 0 to exit   

1: lubridate.sample:::main()
2: code.R#7: force_tz(Sys.time())
3: `[<-`(`*tmp*`, hour(with_tz(new, tzone)) != hour(time), value = NA)
4: `[<-.POSIXct`(`*tmp*`, hour(with_tz(new, tzone)) != hour(time), value = NA)
5: NextMethod(.Generic)
6: hour(with_tz(new, tzone))

Selection:
Comment 1 Doug Mitarotonda 2012-09-03 22:46:43 UTC
Winston Chang has went a little deeper on this since my original posting (from the github thread):

I think I've managed to track down the problem. I've made a minimal R package that reproduces the error:
https://github.com/wch/onetest

library(devtools)
dev_mode(TRUE)
install_github('onetest', 'wch')
one_test()
# x: 2012-09-01 11:00:01   POSIXct POSIXt 
# x + one_const   1346515202 
# x + one_fun()   1346515202 
# x + one_s3()    1346515202 
# x[one_const]    1346515201 
# x[one_fun()]    1346515201 
# x[one_s3(0)]    1346515201 
# x[[one_const]]  1346515201 
# x[[one_fun()]]  1346515201 
# x[[one_s3(0)]]  1346515201 

detach("package:onetest")
onetest:::one_test()
# x: 2012-09-01 10:59:20   POSIXct POSIXt 
# x + one_const   1346515162 
# x + one_fun()   1346515162 
# x + one_s3()    1346515162 
# x[one_const]    1346515161 
# x[one_fun()]    1346515161 
# Error in one_s3(0) : could not find function "one_s3"
You can see the function definitions here: https://github.com/wch/onetest/blob/master/R/onetest.r

I think the problem is in [.POSIXct, with NextMethod("["):


> `[.POSIXct`
function (x, ..., drop = TRUE) 
{
    cl <- oldClass(x)
    class(x) <- NULL
    val <- NextMethod("[")
    class(val) <- cl
    attr(val, "tzone") <- attr(x, "tzone")
    val
}