Skip to content

Optionally strip .recording attribute #64

@aclark02-arcus

Description

@aclark02-arcus

Problem

Because of the .recording attribute stored in riskmetric assessments, this line of code will bloat the assessment object seen below. In my experience assessing all of CRAN (using 'pkg_cran_remote'), it bloats the assessment object from 847 MB to 1.5 GB.

assessment <- suppressMessages(riskmetric::pkg_assess(ref, assessments = metrics))

Here is what the attribute looks like for an example metric:

> x <- assessment$covr_coverage
> attributes(x)$.recording
$expr
{
    covr::coverage_to_list(x$covr_coverage)
}

$attributes
$attributes$names
[1] "filecoverage"  "totalcoverage"


$visible
[1] TRUE

$traceback
NULL

$output
character(0)

Resolution

This helper function may come in handy if you plan on populating the PACKAGES file with assessments instead of scores to make computation more nimble:

strip_recording <- function(assessment) {
  no_recording <-
    lapply(assessment, \(x) {
      structure(
        x,
        .recording = NULL,
        class = setdiff(class(x),
                        "with_eval_recording")
      )
    })
  class(no_recording) <- class(assessment)
  return(no_recording)
}

Usage

Note this solution only works if when pkg_ref() remains a list. The solution is a little "uglier" IMHO if you use the common as_tibble() shown below.

assess <- riskmetric::pkg_ref("askpass", source = "pkg_cran_remote") |>
  #   dplyr::as_tibble() |> # Recommend not using this line, which you aren't.
  riskmetric::pkg_assess()
no_recording <- assess |> strip_recording()

# Observe size diff:
object.size(assess)
> 110,480 bytes
object.size(no_recording)
> 22,608 bytes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions