[Rd] Imports, importFrom slow (for Matrix)

Gábor Csárdi csardi.gabor at gmail.com
Tue Oct 29 15:03:38 CET 2013


Dear All,

before its latest version my package had 'Imports: Matrix' in its
DESCRIPTION file, but it did not import anything in NAMESPACE. Rather,
some functions explicitly loaded Matrix, as they needed. The reason
for this was that importing Matrix is really slow, and only very few
igraph functions need it. (I guess Matrix is slow because of the many
registered names, but that is another question.)

# Empty session:
~$ time Rscript -e 'ls()' > /dev/null
real 0m0.251s
user 0m0.196s
sys 0m0.049s

# Without importing from Matrix:
~$ time Rscript -e 'library(igraph); ls()' > /dev/null
Loading required package: methods
real 0m0.419s
user 0m0.363s
sys 0m0.049s

# Adding importFrom(Matrix, sparseMatrix) to NAMESPACE:
~$ time Rscript -e 'library(igraph); ls()' > /dev/null
Loading required package: methods
real 0m2.963s
user 0m2.844s
sys 0m0.115s

This solution was fine with me, especially because other packages
depending on igraph and using Matrix through igraph worked fine on the
CRAN build servers, as igraph brought Matrix with it. (The build
servers don't have recommended packages like Matrix available by
default.)

Recently, R CMD check does not allow me to list Matrix at Imports
without importing something from it. This is understandable, because
it is an inconsistency after all, but caused some headache for me.

A 3s loading time for a package is IMHO much longer than ideal,
especially that loading R itself is ten times faster. So I definitely
don't want to import from Matrix right now.

The solution I settled with was to include Matrix in 'Suggests', and
the load it selectively, as before. Now some packages depending on
igraph are failing on the CRAN build servers, which don't have Matrix
installed for these packages. (Luckily they are probably not failing
for users, because most users do have the recommended packages.)

In summary, it would be great to speed up imports.

Another solution would be some mechanism that allows me to import from
a package as needed, not at the package loading time. Something like a
delayed importFrom().

Just wanted to bring up this issue.

Best,
Gabor



More information about the R-devel mailing list