[R-pkg-devel] What influences the size of the rdb file in a package

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Sat Oct 30 18:28:17 CEST 2021


On 30/10/2021 11:12 a.m., Bill Dunlap wrote:
> The byte code attached to each function in a package can be surprisingly 
> large.  E.g., the byte code for the c. 300 line function 
> Matrix:::replTmat seems to be c. 4.5 times the size of the raw code:
> 
>  > object.size(Matrix:::replTmat) / 
> object.size(as.function(as.list(Matrix:::replTmat)))
> 5.5 bytes
> 
> [Is there a more direct way to remove byte code from a function?  Or to 
> inspect it?]

You can sort of inspect it using compiler::disassemble, though it's not 
very readable.  You can remove it by assigning to the body, e.g.

body(fn) <- body(fn)

Duncan Murdoch


> 
> Building Matrix with --no-byte-compile reduces the size of R/Matrix.rdx 
> by more than half, from 2.7 MB to 1 MB.
> 
> -Bill
> 
> On Sat, Oct 30, 2021 at 12:00 AM Mosqueira Sanchez, Iago 
> <iago.mosqueira using wur.nl <mailto:iago.mosqueira using wur.nl>> wrote:
> 
>     As far as I can see only classes, methods and functions are present
>     there. I loaded the rdb file and looked at the contents and sizes of
>     objects.
> 
>     Am I right in assuming every method or function imported from another
>     package sits in the database? In another S4 package I see that the
>     largest objects are nls, cor and lm, which we overload for some S4
>     classes.
> 
> 
> 
>     Iago
> 
>     On Fri, 2021-10-29 at 20:21 -0400, Duncan Murdoch wrote:
>      > On 29/10/2021 4:23 p.m., Gábor Csárdi wrote:
>      > > You probably (accidentally?) put some large object into your
>      > > package,
>      > > e.g. a non-function object. But it is hard to say more without
>      > > seeing
>      > > the actual code....
>      >
>      > Yes.  To track it down, you need to understand that an INSTALL
>      > executes
>      > everything in the .R files, and saves every object that was created.
>      > In
>      > a simple package, that's just a bunch of functions, but in more
>      > complicated situations, you may have created some objects in order
>      > to
>      > build functions, even though you don't need them:  but unless you
>      > remove
>      > them, it's very easy to have them included too.
>      >
>      > Duncan Murdoch
>      > > Gabor
>      > >
>      > > On Fri, Oct 29, 2021 at 10:07 PM Mosqueira Sanchez, Iago
>      > > <iago.mosqueira using wur.nl <mailto:iago.mosqueira using wur.nl>> wrote:
>      > > >
>      > > > I am getting warnings in some packages about the size of the R
>      > > > folder
>      > > >
>      > > > * checking installed package size ... NOTE
>      > > >    installed size is 20.5Mb
>      > > >    sub-directories of 1Mb or more:
>      > > >      data   2.4Mb
>      > > >      R     17.8Mb
>      > > >
>      > > > This package contains around 3300 lines of code, if the results
>      > > > of
>      > > >
>      > > > grep -v '^\s*#' *.R | wc
>      > > >
>      > > > are correct.
>      > > >
>      > > > Is this size to be expected? Is there anything I might be
>      > > > missinmg to
>      > > > make it smaller?
>      > > >
>      > > > Thanks,
>      > > >
>      > > >
>      > > > Iago
>      > > > --
>      > > > dr. Iago Mosqueira
>      > > >
>      > > > Wageningen Marine Research
>      > > >
>      > > > Haringkade 1
>      > > > Postbus 68
>      > > > 1976CP, IJmuiden
>      > > >
>      > > > Tel.: +31 (0)317 488 995
>      > > > iago.mosqueira using wur.nl <mailto:iago.mosqueira using wur.nl>
>      > > > ______________________________________________
>      > > > R-package-devel using r-project.org
>     <mailto:R-package-devel using r-project.org> mailing list
>      > > >
>     https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-package-devel&data=04%7C01%7Ciago.mosqueira%40wur.nl%7Cab72634b9fed43fd7a2208d99b3b43cd%7C27d137e5761f4dc1af88d26430abb18f%7C0%7C0%7C637711501535857883%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=E9aOOkVzR46TP2lah4alc%2F%2B5PmFPX27oDV140kBcrEI%3D&reserved=0
>     <https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-package-devel&data=04%7C01%7Ciago.mosqueira%40wur.nl%7Cab72634b9fed43fd7a2208d99b3b43cd%7C27d137e5761f4dc1af88d26430abb18f%7C0%7C0%7C637711501535857883%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=E9aOOkVzR46TP2lah4alc%2F%2B5PmFPX27oDV140kBcrEI%3D&reserved=0>
>      > >
>      > > ______________________________________________
>      > > R-package-devel using r-project.org
>     <mailto:R-package-devel using r-project.org> mailing list
>      > >
>     https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-package-devel&data=04%7C01%7Ciago.mosqueira%40wur.nl%7Cab72634b9fed43fd7a2208d99b3b43cd%7C27d137e5761f4dc1af88d26430abb18f%7C0%7C0%7C637711501535867885%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=ZMc2qL9zGn9u5Tcf8nRNNffZlkMZVbXvdW3pVgrrI0E%3D&reserved=0
>     <https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-package-devel&data=04%7C01%7Ciago.mosqueira%40wur.nl%7Cab72634b9fed43fd7a2208d99b3b43cd%7C27d137e5761f4dc1af88d26430abb18f%7C0%7C0%7C637711501535867885%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=ZMc2qL9zGn9u5Tcf8nRNNffZlkMZVbXvdW3pVgrrI0E%3D&reserved=0>
>      > >
>     ______________________________________________
>     R-package-devel using r-project.org <mailto:R-package-devel using r-project.org>
>     mailing list
>     https://stat.ethz.ch/mailman/listinfo/r-package-devel
>     <https://stat.ethz.ch/mailman/listinfo/r-package-devel>
>



More information about the R-package-devel mailing list