This has methods for various types of things that may not correctly report their object size using object.size. Also, for lists and environments, it will return the object size separately for each element. These are estimates only, and could be inaccurate. Alternative, similar functions include object.size and pryr::object_size. See Details for the special case of functions and their enclosing environments.

objSize(x, quick, enclosingEnvs, .prevEnvirs, ...)

# S3 method for default
objSize(
  x,
  quick = getOption("reproducible.quick", FALSE),
  enclosingEnvs = TRUE,
  .prevEnvirs = list(),
  ...
)

# S3 method for list
objSize(
  x,
  quick = getOption("reproducible.quick", FALSE),
  enclosingEnvs = TRUE,
  .prevEnvirs = list(),
  ...
)

# S3 method for environment
objSize(
  x,
  quick = getOption("reproducible.quick", FALSE),
  enclosingEnvs = TRUE,
  .prevEnvirs = list(),
  ...
)

# S3 method for Path
objSize(
  x,
  quick = getOption("reproducible.quick", FALSE),
  enclosingEnvs = TRUE,
  .prevEnvirs = list(),
  ...
)

# S3 method for `function`
objSize(
  x,
  quick = getOption("reproducible.quick", FALSE),
  enclosingEnvs = TRUE,
  .prevEnvirs = list(),
  ...
)

objSizeSession(sumLevel = Inf, enclosingEnvs = TRUE, .prevEnvirs = list())

Arguments

x

An object

quick

Logical. Only some methods use this. e.g., Path class objects. In which case, file.size will be used instead of object.size.

enclosingEnvs

Logical indicating whether to include enclosing environments. Default TRUE.

.prevEnvirs

For internal account keeping to identify and prevent duplicate counting

...

Additional arguments (currently unused)

sumLevel

Numeric, indicating at which depth in the list of objects should the object sizes be summed (summarized). Default is Inf, meaning no sums. Currently, the only option other than Inf is 1: objSizeSession(1), which gives the size of each package.

Details

For functions, a user can include the enclosing environment as described https://www.r-bloggers.com/using-closures-as-objects-in-r/ and http://adv-r.had.co.nz/memory.html. It is not entirely clear which estimate is better. However, if the enclosing environment is the .GlobalEnv, it will not be included even though enclosingEnvs = TRUE.

objSizeSession will give the size of the whole session, including loaded packages. Because of the difficulties in calculating the object size of base and methods packages and Autoloads, these are omitted.

Examples

library(utils) foo <- new.env() foo$b <- 1:10 foo$d <- 1:10 objSize(foo) # all the elements in the environment
#> $`foo$b` #> 96 bytes #> #> $`foo$d` #> 96 bytes #> #> $foo #> 56 bytes #>
object.size(foo) # different - only measuring the environment as an object
#> 56 bytes
object.size(prepInputs) # only the function, without its enclosing environment
#> 46984 bytes
objSize(prepInputs) # the function, plus its enclosing environment
#> $`%<%` #> 24120 bytes #> #> $`%C%` #> 292504 bytes #> #> $appendChecksumsTable #> 28480 bytes #> #> $argsToRemove #> 1896 bytes #> #> $asPath #> 1928 bytes #> #> $asPath.character #> 10824 bytes #> #> $asPath.null #> 1480 bytes #> #> $assessDataType #> 1784 bytes #> #> $assessDataType.default #> 3808 bytes #> #> $assessDataType.Raster #> 38024 bytes #> #> $assessDataType.RasterStack #> 21832 bytes #> #> $assessDataTypeGDAL #> 109368 bytes #> #> $assessGoogle #> 70304 bytes #> #> $attemptGDAL #> 8928 bytes #> #> $available.packagesMem #> 3792 bytes #> #> $basename2 #> 4768 bytes #> #> $bigRastersTmpFile #> 2200 bytes #> #> $bigRastersTmpFolder #> 3448 bytes #> #> $bufferWarningSuppress #> 27384 bytes #> #> $Cache #> 22688 bytes #> #> $CacheDBFile #> 31776 bytes #> #> $CacheDBTableName #> 47392 bytes #> #> $CacheDigest #> 112568 bytes #> #> $CacheIsACache #> 15240 bytes #> #> $CacheStorageDir #> 7720 bytes #> #> $CacheStoredFile #> 29224 bytes #> #> $cc #> 10224 bytes #> #> $checkAndMakeCloudFolderID #> 19088 bytes #> #> $checkFutures #> 11552 bytes #> #> $checkGDALVersion #> 12808 bytes #> #> $checkoutVersion #> 247600 bytes #> #> $checkPath #> 5256 bytes #> #> $Checksums #> 7840 bytes #> #> $chooseCRANmirror2 #> 1120 bytes #> #> $clearCache #> 12360 bytes #> #> $clearStubArtifacts #> 4696 bytes #> #> $cloudCache #> 3776 bytes #> #> $cloudCheckOld #> 4000 bytes #> #> $cloudDownload #> 15288 bytes #> #> $cloudDownloadRasterBackend #> 23664 bytes #> #> $cloudFolderFromCacheRepo #> 6760 bytes #> #> $cloudSyncCacheOld #> 5616 bytes #> #> $cloudUpload #> 16616 bytes #> #> $cloudUploadFromCache #> 11360 bytes #> #> $cloudUploadRasterBackends #> 7360 bytes #> #> $cloudWriteOld #> 4808 bytes #> #> $compareNA #> 12544 bytes #> #> $convertPaths #> 28456 bytes #> #> $convertRasterPaths #> 49840 bytes #> #> $Copy #> 5616 bytes #> #> $copyFile #> 33328 bytes #> #> $copySingleFile #> 276680 bytes #> #> $createCache #> 14168 bytes #> #> $cropInputs #> 2056 bytes #> #> $cropInputs.default #> 1592 bytes #> #> $cropInputs.sf #> 154696 bytes #> #> $cropInputs.spatialObjects #> 41280 bytes #> #> $dbConnectAll #> 5712 bytes #> #> $dealWithCores #> 7688 bytes #> #> $dealWithRasters #> 27920 bytes #> #> $determineFilename #> 102848 bytes #> #> $determineNestedTags #> 104896 bytes #> #> $devModeFn1 #> 32112 bytes #> #> $dlGeneric #> 46688 bytes #> #> $dlGoogle #> 197976 bytes #> #> $downloadFile #> 677272 bytes #> #> $downloadRemote #> 342592 bytes #> #> $driveLs #> 9616 bytes #> #> $extractFromArchive #> 538808 bytes #> #> $fastMask #> 54528 bytes #> #> $Filenames #> 4744 bytes #> #> $findGDAL #> 58424 bytes #> #> $fixErrors #> 2584 bytes #> #> $fixErrors.default #> 2120 bytes #> #> $fixErrors.sf #> 80776 bytes #> #> $fixErrors.SpatialPolygons #> 94200 bytes #> #> $getArtifact #> 28832 bytes #> #> $getCacheId #> 30208 bytes #> #> $getCacheRepos #> 23040 bytes #> #> $getCRANrepos #> 34016 bytes #> #> $getFunctionName #> 552952 bytes #> #> $getGDALVersion #> 43216 bytes #> #> $getLocalTags #> 40808 bytes #> #> $getUserTags #> 57008 bytes #> #> $installedVersions #> 110480 bytes #> #> $installedVersionsQuick #> 116976 bytes #> #> $installVersions #> 946320 bytes #> #> $internetExists #> 46896 bytes #> #> $isInteractive #> 840 bytes #> #> $isOrHasRaster #> 78752 bytes #> #> $isTRUEorForce #> 5880 bytes #> #> $isWindows #> 3544 bytes #> #> $keepCache #> 10664 bytes #> #> $knownArchiveExtensions #> 432 bytes #> #> $knownInternalArchiveExtensions #> 304 bytes #> #> $knownSystemArchiveExtensions #> 176 bytes #> #> $linkOrCopy #> 121392 bytes #> #> $loadFromCache #> 16552 bytes #> #> $makeMemoisable #> 1552 bytes #> #> $makeMemoisable.default #> 1088 bytes #> #> $maskInputs #> 1888 bytes #> #> $maskInputs.Raster #> 5992 bytes #> #> $maskInputs.sf #> 107768 bytes #> #> $maskInputs.Spatial #> 108992 bytes #> #> $maskWithRasterNAs #> 19016 bytes #> #> $mergeCache #> 9880 bytes #> #> $missingFiles #> 38056 bytes #> #> $missingUnrarMess #> 232 bytes #> #> $moveAttributes #> 28808 bytes #> #> $newLibPaths #> 9816 bytes #> #> $nextNumericName #> 97200 bytes #> #> $normPath #> 4744 bytes #> #> $objSize #> 2432 bytes #> #> $objSize.default #> 3496 bytes #> #> $objSize.environment #> 35144 bytes #> #> $objSize.function #> 48056 bytes #> #> $objSize.list #> 127880 bytes #> #> $objSize.Path #> 6984 bytes #> #> $objSizeSession #> 143520 bytes #> #> $package_dependenciesMem #> 102240 bytes #> #> $pickFirstVersion #> 17000 bytes #> #> $pkgDep #> 1066856 bytes #> #> $pkgDep2 #> 62152 bytes #> #> $pkgSnapshot #> 30712 bytes #> #> $postProcess #> 1720 bytes #> #> $postProcess.default #> 1256 bytes #> #> $postProcess.list #> 8872 bytes #> #> $postProcess.quosure #> 1648 bytes #> #> $postProcess.sf #> 44200 bytes #> #> $postProcess.spatialObjects #> 5336 bytes #> #> $postProcessAllSpatial #> 52976 bytes #> #> $postProcessChecks #> 49936 bytes #> #> $prepInputs #> 46984 bytes #> #> $preProcess #> 1024000 bytes #> #> $projectInputs #> 1888 bytes #> #> $projectInputs.default #> 1424 bytes #> #> $projectInputs.Raster #> 84552 bytes #> #> $projectInputs.sf #> 91944 bytes #> #> $projectInputs.Spatial #> 43432 bytes #> #> $RCurlMess #> 232 bytes #> #> $reproducibleOptions #> 22400 bytes #> #> $Require #> 354824 bytes #> #> $retry #> 57912 bytes #> #> $rmFromCache #> 48752 bytes #> #> $rmFromCloudFolder #> 93528 bytes #> #> $rndstr #> 29240 bytes #> #> $roundToRes #> 44720 bytes #> #> $saveToCache #> 30216 bytes #> #> $searchFull #> 37224 bytes #> #> $searchFullEx #> 1120 bytes #> #> $setMinMaxIfNeeded #> 29840 bytes #> #> $showCache #> 9648 bytes #> #> $showLocalRepo2 #> 13200 bytes #> #> $showLocalRepo3 #> 4856 bytes #> #> $showLocalRepo3Mem #> 88680 bytes #> #> $tempdir2 #> 5680 bytes #> #> $unmakeMemoisable #> 1584 bytes #> #> $unmakeMemoisable.default #> 1088 bytes #> #> $useDBI #> 12904 bytes #> #> $useETM #> 14544 bytes #> #> $verboseDF1 #> 39560 bytes #> #> $verboseDF2 #> 36000 bytes #> #> $verboseDF3 #> 36096 bytes #> #> $verboseMessage1 #> 8792 bytes #> #> $verboseMessage2 #> 5464 bytes #> #> $verboseMessage3 #> 10160 bytes #> #> $verboseTime #> 4208 bytes #> #> $writeChecksumsTable #> 24960 bytes #> #> $writeFuture #> 17832 bytes #> #> $writeOutputs #> 2360 bytes #> #> $writeOutputs.default #> 4400 bytes #> #> $writeOutputs.quosure #> 6032 bytes #> #> $writeOutputs.Raster #> 205488 bytes #> #> $writeOutputs.sf #> 68192 bytes #> #> $writeOutputs.Spatial #> 61776 bytes #>
# Size of all packages; includes their imported functions if (FALSE) { bar <- objSizeSession(1) print(bar, units = "auto") } os1 <- object.size(as.environment("package:reproducible")) os2 <- objSize(as.environment("package:reproducible")) (os1) # very small -- just the environment container
#> 648 bytes
sum(unlist(os2)) # around 13 MB, with all functions, objects
#> [1] 11970728
# and imported functions