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

problem with loadMethod for lubridate in Rscript #314

Closed
mccreigh opened this issue Apr 22, 2015 · 12 comments

Comments

@mccreigh
Copy link

commented Apr 22, 2015

Compose the Rscript with file name lubridateTest.Rsh:

#! /usr/bin/RScript
lubridate::round_date(Sys.time(),'minute')

Run it:

jamesmcc@chimayo:~> ./lubridateTest.Rsh 
Error in x - eseconds(1) : could not find function "loadMethod"
Calls: <Anonymous> ... as.POSIXct -> ceiling_date -> floor_date -> update -> -
recover called non-interactively; frames dumped, use debugger() to view

This works however:

#! /usr/bin/RScript
library(lubridate)
lubridate::round_date(Sys.time(),'minute')

Run it:

jamesmcc@chimayo:~> ./lubridateTest.Rsh 
Loading required package: methods
[1] "2015-04-22 13:25:00 MDT"

I have no idea why, but it just is this way. I'm curious to know however.
Thanks,
J

@vspinu

This comment has been minimized.

Copy link
Member

commented Apr 22, 2015

This applies to all S4 packages. The problem is that methods package is not attached from Rscript. This will work:

#! /usr/bin/Rscript
library(methods)
lubridate::round_date(Sys.time(),'minute')

I think there is a way around it, like explicitly calling require(methods) in evalOnLoad, but I am not sure we should bother with that. @hadley should know better what is the recommended way to deal with this issue.

@hadley

This comment has been minimized.

Copy link
Member

commented Apr 23, 2015

I think this might be fixed in 3.2

@vspinu

This comment has been minimized.

Copy link
Member

commented Apr 23, 2015

It's still there in today's devel but under a different form:

Error in dseconds(1) : could not find function "new"
Calls: <Anonymous> ... as.POSIXct -> ceiling_date -> floor_date -> update -> dseconds
In addition: Warning message:
no function found corresponding to methods exports from ‘lubridate’ for: ‘show’ 
Execution halted
@hadley

This comment has been minimized.

Copy link
Member

commented Apr 23, 2015

Are you importing the methods package and new etc?

@vspinu

This comment has been minimized.

Copy link
Member

commented Apr 23, 2015

Are you importing the methods package and new etc?

Nope. methods is in Depends and no explicit imports for new, show etc are there. I guess that was it.

@vspinu

This comment has been minimized.

Copy link
Member

commented Apr 23, 2015

Ok. I have imported new and show. Now I am getting

Error in .setupMethodsTables(fdef, initialize = TRUE) : 
  trying to get slot "group" from an object of a basic class ("NULL") with no slots
Calls: <Anonymous> ... getMethodsForDispatch -> .getMethodsTable -> .setupMethodsTables

Importing the whole methods package results into:

Error in x - dseconds(1) : could not find function "loadMethod"
Calls: <Anonymous> ... as.POSIXct -> ceiling_date -> floor_date -> update -> -

Explicitly importing loadMethods doesn't help.

@hadley

This comment has been minimized.

Copy link
Member

commented Apr 23, 2015

Does R CMD check give anything helpful?

@vspinu

This comment has been minimized.

Copy link
Member

commented Apr 24, 2015

Does R CMD check give anything helpful?

Nope.

hadley added a commit that referenced this issue May 13, 2015

@hadley

This comment has been minimized.

Copy link
Member

commented May 13, 2015

I now get

Rscript -e "lubridate::round_date(Sys.time(),'minute')"
[1] "2015-05-13 13:15:00 CDT"

I don't know how to make sure we've correctly imported every needed generic from methods though.

@vspinu

This comment has been minimized.

Copy link
Member

commented May 13, 2015

Rscript -e "lubridate::round_date(Sys.time(),'minute')"

Hm. It works for me as well. So it was magically fixed since then.

I don't know how to make sure we've correctly imported every needed generic from methods though.

We can add this as a test to travis. So each time we rely on a method it's spotted.

@hadley

This comment has been minimized.

Copy link
Member

commented May 13, 2015

@vspinu it's not exactly magic - I made some commits to fix it ;)

@vspinu

This comment has been minimized.

Copy link
Member

commented May 13, 2015

Aha. I see. It's 8fa6ba3.


I have added this one to the tests. You might want to have a lot at it.

The call executes fine on test("path/to/lubridate") but not on check("path/to/lubridate"). I am deactivating it on Travis because of this. I also don't want to have a separate script for that because of the convenience of devtools::test. Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.