R Under development (unstable) (2025-05-01 r88184 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library("profmem") > > if (capabilities("profmem")) { + + ## Defaults to on_error = "ignore") + p <- profmem({ + x <- raw(1000) + stop("Woops!") + }) + print(p) + + + for (on_error in c("ignore", "warning", "error")) { + message(sprintf("- profmem(..., on_error = \"%s\")", on_error)) + res <- tryCatch({ + profmem({ + x <- raw(1000) + stop("Woops!") + }, on_error = on_error) + }, error = identity, warning = identity) + if (on_error == "ignore") { + stopifnot(inherits(res, "Rprofmem")) + } else { + stopifnot(inherits(res, on_error)) + } + } + + } ## if (capabilities("profmem")) Rprofmem memory profiling of: { x <- raw(1000) stop("Woops!") } Memory allocations: Number of 'new page' entries not displayed: 5 what bytes calls 3 alloc 256 4 alloc 488 5 alloc 488 6 alloc 1072 7 alloc 1048 raw() 8 alloc 888 9 alloc 3624 10 alloc 3624 11 alloc 1072 12 alloc 224 13 alloc 504 14 alloc 960 15 alloc 416 16 alloc 504 17 alloc 816 stop() 18 alloc 3256 stop() 19 alloc 3256 stop() 20 alloc 1072 stop() 21 alloc 200 stop() 22 alloc 424 stop() 23 alloc 800 stop() 24 alloc 352 stop() 26 alloc 424 stop() 28 alloc 440 29 alloc 1344 30 alloc 1344 31 alloc 1072 32 alloc 184 33 alloc 216 34 alloc 528 35 alloc 1648 36 alloc 1648 37 alloc 1072 38 alloc 256 39 alloc 456 40 alloc 216 42 alloc 256 total 36448 Note, an error occurred while evaluating the expression: Woops! - profmem(..., on_error = "ignore") - profmem(..., on_error = "warning") - profmem(..., on_error = "error") > > proc.time() user system elapsed 0.21 0.01 0.21