[Rd] Imports, importFrom slow (for Matrix)

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Oct 29 15:11:06 CET 2013


On 29/10/2013 14:03, Gábor Csárdi wrote:
> 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().

That is what Matrix:: does.  There is nothing like enough here for us to 
tell why it would not suffice for you.  (If you want to import something 
occasionally and then use it very many times, make a local copy.)

>
> Just wanted to bring up this issue.
>
> Best,
> Gabor
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list