[R-pkg-devel] how to prevent a small package from yielding a large installed size?

Daniel Kelley D@n@Ke||ey @end|ng |rom D@|@C@
Mon Jun 15 21:34:09 CEST 2020


I found as Duncan, but then I saw https://stackoverflow.com/questions/54144239/how-to-use-saverds-refhook-parameter and found more info as follows.  (It will take me a while to go through the output, but basically I am seeing code from the "oce" package, which makes me think I ought to get rid of the "Imports:" listing in my DESCRIPTION and instead use "Suggests:" and then grab things at runtime, as needed.  Maybe that will trim down the rds file, e.g. I see in the output from below about 1000 lines that correspond to a particular oce function (or set of specialized versions of a generic, actually), which yields size 38649 in a references$`env` entry.

unser <- function(s){
  i <- as.numeric(s)
  return(rdx$variables[[i]])
}

readRDB <- function(filename, offset, size, type = 'gzip') {
       f <- file(filename, 'rb')
       on.exit(close(f))
       seek(f, offset + 4)
       unserialize(memDecompress(readBin(f, 'raw', size - 4), type), refhook=unser)
}



Dan E. Kelley [he/him/his 314ppm]
Professor and Senator
Department of Oceanography
Dalhousie University
PO BOX 15000
Halifax, NS, Canada B3H 4R2
(902)494-1694  Dan.Kelley using Dal.CA<mailto:Dan.Kelley using Dal.CA>









On Jun 15, 2020, at 4:12 PM, Duncan Murdoch <murdoch.duncan using gmail.com<mailto:murdoch.duncan using gmail.com>> wrote:

CAUTION: The Sender of this email is not from within Dalhousie.

On 15/06/2020 1:24 p.m., Ivan Krylov wrote:
On Mon, 15 Jun 2020 12:52:20 -0400
Duncan Murdoch <murdoch.duncan using gmail.com<mailto:murdoch.duncan using gmail.com>> wrote:

maybe someone else can suggest how to read an object from
the .rdb file using R code.  Internally R uses C code for this.

This function seems to work for me:

# filename: the .rdb file
# offset, size: the pair of values from the .rdx
# type: 'gzip' if $compressed is TRUE, 'bzip2' for 2, 'xz' for 3
readRDB <- function(filename, offset, size, type = 'gzip') {
     f <- file(filename, 'rb')
     on.exit(close(f))
     seek(f, offset + 4)
     unserialize(memDecompress(readBin(f, 'raw', size - 4), type))
}


Thanks, though it didn't work for me.  I get

Error in unserialize(memDecompress(readBin(f, "raw", size - 4), type)) :
 no restore method available

on every object I tried.  However, maybe Dan will have better luck.

Duncan Murdoch


	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list