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
#> 56696 bytes
objSize(prepInputs) # the function, plus its enclosing environment
#> $`%<%` #> 24120 bytes #> #> $`%C%` #> 292504 bytes #> #> $appendChecksumsTable #> 142640 bytes #> #> $argsToRemove #> 2032 bytes #> #> $asPath #> 1928 bytes #> #> $asPath.character #> 10824 bytes #> #> $asPath.null #> 1480 bytes #> #> $assessDataType #> 1784 bytes #> #> $assessDataType.default #> 3808 bytes #> #> $assessDataType.Raster #> 30856 bytes #> #> $assessDataType.RasterStack #> 21832 bytes #> #> $assessDataTypeGDAL #> 3344 bytes #> #> $assessGoogle #> 81240 bytes #> #> $attemptGDAL #> 12184 bytes #> #> $basename2 #> 4768 bytes #> #> $bigRastersTmpFile #> 2200 bytes #> #> $bigRastersTmpFolder #> 4112 bytes #> #> $Cache #> 22688 bytes #> #> $CacheDBFile #> 32024 bytes #> #> $CacheDBTableName #> 47640 bytes #> #> $CacheDigest #> 123560 bytes #> #> $CacheIsACache #> 21936 bytes #> #> $CacheStorageDir #> 7968 bytes #> #> $CacheStoredFile #> 28112 bytes #> #> $captureWarningsToAttr #> 57104 bytes #> #> $cc #> 10224 bytes #> #> $checkAndMakeCloudFolderID #> 22624 bytes #> #> $checkColors #> 10760 bytes #> #> $checkFutures #> 11552 bytes #> #> $checkGDALVersion #> 12808 bytes #> #> $checkoutVersion #> 2992 bytes #> #> $Checksums #> 9064 bytes #> #> $clearCache #> 12360 bytes #> #> $clearStubArtifacts #> 4696 bytes #> #> $cloudCache #> 3776 bytes #> #> $cloudCheckOld #> 4000 bytes #> #> $cloudDownload #> 15112 bytes #> #> $cloudDownloadRasterBackend #> 25608 bytes #> #> $cloudFolderFromCacheRepo #> 6760 bytes #> #> $cloudSyncCacheOld #> 5616 bytes #> #> $cloudUpload #> 18280 bytes #> #> $cloudUploadFromCache #> 12520 bytes #> #> $cloudUploadRasterBackends #> 9024 bytes #> #> $cloudWriteOld #> 4808 bytes #> #> $compareNA #> 12496 bytes #> #> $convertPaths #> 28440 bytes #> #> $convertRasterPaths #> 49840 bytes #> #> $Copy #> 5616 bytes #> #> $copyFile #> 33328 bytes #> #> $copySingleFile #> 276680 bytes #> #> $createCache #> 14416 bytes #> #> $cropInputs #> 2584 bytes #> #> $cropInputs.default #> 1592 bytes #> #> $cropInputs.sf #> 199392 bytes #> #> $cropInputs.spatialClasses #> 67192 bytes #> #> $cropReprojMaskWGDAL #> 74408 bytes #> #> $datatypeVals #> 8080 bytes #> #> $dbConnectAll #> 5960 bytes #> #> $dealWithCores #> 7856 bytes #> #> $dealWithRasters #> 29376 bytes #> #> $dealWithRastersOnRecovery #> 178792 bytes #> #> $determineFilename #> 141936 bytes #> #> $determineNestedTags #> 106272 bytes #> #> $devModeFn1 #> 32280 bytes #> #> $differentRasters #> 33544 bytes #> #> $dlGeneric #> 53320 bytes #> #> $dlGoogle #> 216704 bytes #> #> $downloadFile #> 84952 bytes #> #> $downloadRemote #> 56304 bytes #> #> $driveLs #> 12536 bytes #> #> $dtp #> 864 bytes #> #> $dtps #> 1232 bytes #> #> $extractFromArchive #> 69744 bytes #> #> $fastMask #> 56232 bytes #> #> $file.move #> 27688 bytes #> #> $fileExt #> 12920 bytes #> #> $Filenames #> 5264 bytes #> #> $filePathSansExt #> 3832 bytes #> #> $findGDAL #> 71584 bytes #> #> $fixErrors #> 3112 bytes #> #> $fixErrors.default #> 2648 bytes #> #> $fixErrors.Raster #> 36712 bytes #> #> $fixErrors.sf #> 94792 bytes #> #> $fixErrors.SpatialPolygons #> 96768 bytes #> #> $getArtifact #> 28832 bytes #> #> $getCacheId #> 30208 bytes #> #> $getCacheRepos #> 25728 bytes #> #> $getFunctionName #> 553112 bytes #> #> $getGDALVersion #> 54400 bytes #> #> $getUserTags #> 56984 bytes #> #> $internetExists #> 46896 bytes #> #> $isAbsolutePath #> 43784 bytes #> #> $isDirectory #> 26640 bytes #> #> $isFile #> 24592 bytes #> #> $isInteractive #> 840 bytes #> #> $isLongLat #> 7728 bytes #> #> $isOrHasRaster #> 78752 bytes #> #> $isTRUEorForce #> 5880 bytes #> #> $isWindows #> 3544 bytes #> #> $keepCache #> 10664 bytes #> #> $knownArchiveExtensions #> 432 bytes #> #> $knownInternalArchiveExtensions #> 304 bytes #> #> $knownSystemArchiveExtensions #> 176 bytes #> #> $linkOrCopy #> 135032 bytes #> #> $loadFile #> 5576 bytes #> #> $loadFromCache #> 109568 bytes #> #> $makeMemoisable #> 1552 bytes #> #> $makeMemoisable.default #> 1088 bytes #> #> $maskInputs #> 1888 bytes #> #> $maskInputs.Raster #> 12064 bytes #> #> $maskInputs.sf #> 22168 bytes #> #> $maskInputs.Spatial #> 5032 bytes #> #> $maskWithRasterNAs #> 25232 bytes #> #> $MaxVals #> 1232 bytes #> #> $MaxValsFlts #> 464 bytes #> #> $mergeCache #> 9880 bytes #> #> $messageCache #> 3640 bytes #> #> $messageColoured #> 48320 bytes #> #> $messageDF #> 81680 bytes #> #> $messagePrepInputs #> 3704 bytes #> #> $messageQuestion #> 6528 bytes #> #> $MinVals #> 1232 bytes #> #> $MinValsFlts #> 464 bytes #> #> $missingFiles #> 38056 bytes #> #> $missingUnrarMess #> 232 bytes #> #> $moveAttributes #> 28808 bytes #> #> $movedCache #> 16992 bytes #> #> $nextNumericName #> 97200 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 #> #> $postProcess #> 1720 bytes #> #> $postProcess.default #> 1256 bytes #> #> $postProcess.list #> 8872 bytes #> #> $postProcess.quosure #> 1648 bytes #> #> $postProcess.sf #> 52304 bytes #> #> $postProcess.spatialClasses #> 6648 bytes #> #> $postProcessAllSpatial #> 71456 bytes #> #> $postProcessChecks #> 53864 bytes #> #> $prepInputs #> 56696 bytes #> #> $preProcess #> 190512 bytes #> #> $preProcessParams #> 401312 bytes #> #> $progressBarCode #> 19176 bytes #> #> $proj6Warn #> 136 bytes #> #> $projectInputs #> 2416 bytes #> #> $projectInputs.default #> 1424 bytes #> #> $projectInputs.Raster #> 101256 bytes #> #> $projectInputs.sf #> 82848 bytes #> #> $projectInputs.Spatial #> 47176 bytes #> #> $projNotWKT2warn #> 136 bytes #> #> $RCurlMess #> 232 bytes #> #> $rebuildColors #> 71440 bytes #> #> $reproducibleOptions #> 17400 bytes #> #> $requireNamespaceMsg #> 23824 bytes #> #> $retry #> 63584 bytes #> #> $rmFromCache #> 43864 bytes #> #> $rmFromCloudFolder #> 19480 bytes #> #> $rndstr #> 29240 bytes #> #> $roundTo6Dec #> 14568 bytes #> #> $roundToRes #> 44672 bytes #> #> $saveFileInCacheFolder #> 62952 bytes #> #> $saveToCache #> 38288 bytes #> #> $searchFull #> 37224 bytes #> #> $searchFullEx #> 1120 bytes #> #> $setMinMaxIfNeeded #> 76592 bytes #> #> $showCache #> 9648 bytes #> #> $studyAreaName #> 5200 bytes #> #> $suppressWarningsSpecific #> 54592 bytes #> #> $unmakeMemoisable #> 1584 bytes #> #> $unmakeMemoisable.default #> 1088 bytes #> #> $updateFilenameSlots #> 77256 bytes #> #> $useDBI #> 7936 bytes #> #> $useETM #> 16544 bytes #> #> $verboseDF1 #> 39560 bytes #> #> $verboseDF2 #> 36000 bytes #> #> $verboseDF3 #> 36096 bytes #> #> $verboseMessage1 #> 10976 bytes #> #> $verboseMessage2 #> 7368 bytes #> #> $verboseMessage3 #> 12096 bytes #> #> $verboseTime #> 4208 bytes #> #> $writeChecksumsTable #> 24960 bytes #> #> $writeFuture #> 8928 bytes #> #> $writeOutputs #> 2360 bytes #> #> $writeOutputs.default #> 4400 bytes #> #> $writeOutputs.quosure #> 6032 bytes #> #> $writeOutputs.Raster #> 726256 bytes #> #> $writeOutputs.sf #> 75464 bytes #> #> $writeOutputs.Spatial #> 10792 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] 13269136
# and imported functions