[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 12:38:57 CEST 2021


On 30/10/2021 3:00 a.m., Mosqueira Sanchez, Iago 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.

I think imports just get a small record saying where to get the object 
from, they don't get full copies.  That way if you import foo::bar, and 
the foo package gets updated, your package will use the latest version.

If you want to find out what is taking up all the space, this is what 
you can do.  Suppose your package is called "foo".  Then read the index 
to the R objects using

rdx <- readRDS(system.file("R/foo.rdx", package = "foo"))

Then rdx$variables will be a named list.  The names are the names of the 
variables, and the values are offsets and sizes of each variable in the 
foo.rdb file.  So this will print all the sizes from smallest to largest:

sort(sapply(rdx$variables, function(x) x[2]))

If none of those are very big, you could look at

sapply(rdx$references, function(x) x[2]))

for the sizes of the references to other environments.  These are harder 
to interpret, because they get names like "env::3", unlike the 
variables, which have the name they use in R. I suppose you could figure 
out how lazyLoadDBfetch() works and read one of them to see what's in 
it, but I haven't done that.

Duncan Murdoch

> 
> 
> 
> 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> 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
>>>> ______________________________________________
>>>> 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
>>>
>>> ______________________________________________
>>> 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
>>>



More information about the R-package-devel mailing list