Skip to content

[R-pkg-devel] loadMethod() not available with Rscript

6 messages · Thierry Onkelinx, Joshua Ulrich, Dirk Eddelbuettel +1 more

#
Dear all,

Could someone explain this to me? I have a simple script (see below).
my_function() is an S4 method. The package imports all functions from
methods that it uses.

When I run the script in a vanilla R session it works. When using
Rscript I get the error: Error in loadMethod(function (x, ...)  :
could not find function "loadMethod"

loadMethod() is NOT used in mypackage and not imported.

library(mypackage)
my_function()

Best regards,

ir. Thierry Onkelinx
Statisticus/ Statiscian

Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE
AND FOREST
Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
thierry.onkelinx at inbo.be
Kliniekstraat 25, B-1070 Brussel
www.inbo.be

///////////////////////////////////////////////////////////////////////////////////////////
To call in the statistician after the experiment is done may be no
more than asking him to perform a post-mortem examination: he may be
able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does
not ensure that a reasonable answer can be extracted from a given body
of data. ~ John Tukey
///////////////////////////////////////////////////////////////////////////////////////////


Van 14 tot en met 19 december 2017 verhuizen we uit onze vestiging in
Brussel naar het Herman Teirlinckgebouw op de site Thurn & Taxis.
Vanaf dan ben je welkom op het nieuwe adres: Havenlaan 88 bus 73, 1000 Brussel.
#
Hi Thierry,

On Wed, Sep 20, 2017 at 7:45 AM, Thierry Onkelinx
<thierry.onkelinx at inbo.be> wrote:
Rscript does not load/attach the "methods" package like is done in an
interactive R session.

Perhaps your package uses a package that needs methods::loadMethod(),
but does not import it correctly?

  
    
#
Dear Joshua,

Thanks for your prompt reply.

I had a look at all dependencies and none of them use loadMethod(). So
the culprit is probably one of their dependencies.

What would be the best way to deal with this? add library(methods) to
the script or import loadMethod() via the NAMESPACE?

Best regards,

ir. Thierry Onkelinx
Statisticus/ Statiscian

Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE
AND FOREST
Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
thierry.onkelinx at inbo.be
Kliniekstraat 25, B-1070 Brussel
www.inbo.be

///////////////////////////////////////////////////////////////////////////////////////////
To call in the statistician after the experiment is done may be no
more than asking him to perform a post-mortem examination: he may be
able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does
not ensure that a reasonable answer can be extracted from a given body
of data. ~ John Tukey
///////////////////////////////////////////////////////////////////////////////////////////


Van 14 tot en met 19 december 2017 verhuizen we uit onze vestiging in
Brussel naar het Herman Teirlinckgebouw op de site Thurn & Taxis.
Vanaf dan ben je welkom op het nieuwe adres: Havenlaan 88 bus 73, 1000 Brussel.

///////////////////////////////////////////////////////////////////////////////////////////



2017-09-20 14:48 GMT+02:00 Joshua Ulrich <josh.m.ulrich at gmail.com>:
#
Thierry,

This has always been a considerable puzzle, and the source of some amusement,
to me.  It is a clear design bug in Rscript because _code that would
otherwise work_ will not if it happens to rely on library(methods). S4 comes
to mind.  This has also been answered at least a few times on SO.

Now, 'r' from littler always did this differently and lods methods, just like
R itself does.  And 'r' still starts (way) faster as I once documented in a
blog post.

If someone from R Core reads this and nods silently: please put this to rest
and make sure Rscript also loads the methods package.

Dirk
#
On Wed, 2017-09-20 at 09:45 -0500, Dirk Eddelbuettel wrote:
We have been here before, most recently in 2016

https://bugs.r-project.org/bugzilla/show_bug.cgi?id=16921

There are opinions on both sides, of course, but the decision rests in
the hands of those who use extensively for its original purpose (i.e.
running short snippets of R code) and for whom the overhead from
loading the methods package is still unacceptable, despite being
substantially reduced since this decision was made 10 years ago.

Martyn
1 day later
#
On 20 September 2017 at 16:44, Martyn Plummer wrote:
| On Wed, 2017-09-20 at 09:45 -0500, Dirk Eddelbuettel wrote:
| > Thierry,
| > 
| > This has always been a considerable puzzle, and the source of some amusement,
| > to me.  It is a clear design bug in Rscript because _code that would
| > otherwise work_ will not if it happens to rely on library(methods). S4 comes
| > to mind.  This has also been answered at least a few times on SO.
| > 
| > Now, 'r' from littler always did this differently and lods methods, just like
| > R itself does.  And 'r' still starts (way) faster as I once documented in a
| > blog post.
| > 
| > If someone from R Core reads this and nods silently: please put this to rest
| > and make sure Rscript also loads the methods package.
| 
| We have been here before, most recently in 2016
| 
| https://bugs.r-project.org/bugzilla/show_bug.cgi?id=16921
| 
| There are opinions on both sides, of course, but the decision rests in
| the hands of those who use extensively for its original purpose (i.e.
| running short snippets of R code) and for whom the overhead from
| loading the methods package is still unacceptable, despite being
| substantially reduced since this decision was made 10 years ago.

Sure, I don't care. I wrote littler for my purposes.

But to be honet I still find it strange that you all troll your users by
withholding one (base) package on one platform only, but your call.

Dirk