| 1 |
library("profmem") |
| 2 |
|
| 3 |
message("readRprofmem() ...") |
| 4 |
|
| 5 |
message(" - corrupt file") |
| 6 |
|
| 7 |
broken <- system.file("extdata", "broken.Rprofmem.out", package = "profmem") |
| 8 |
|
| 9 |
bfr <- readLines(broken) |
| 10 |
cat("readLines(broken):\n") |
| 11 |
print(bfr) |
| 12 |
|
| 13 |
raw <- readRprofmem(broken, as = "raw") |
| 14 |
cat("readRprofmem(broken, as = 'raw'):\n") |
| 15 |
print(raw) |
| 16 |
stopifnot( |
| 17 |
length(raw) == length(bfr), |
| 18 |
all(raw == bfr) |
| 19 |
) |
| 20 |
|
| 21 |
message("readRprofmem(broken, as = 'fixed'):\n") |
| 22 |
fixed <- readRprofmem(broken, as = "fixed") |
| 23 |
print(fixed) |
| 24 |
stopifnot(length(fixed) >= length(bfr)) |
| 25 |
|
| 26 |
p <- readRprofmem(broken, as = "Rprofmem") |
| 27 |
cat("readRprofmem(broken, as = 'Rprofmem'):\n") |
| 28 |
print(p) |
| 29 |
str(p) |
| 30 |
stopifnot(nrow(p) == length(fixed)) |
| 31 |
|
| 32 |
|
| 33 |
message(" - empty file") |
| 34 |
|
| 35 |
options(profmem.debug = TRUE) |
| 36 |
|
| 37 |
empty <- tempfile() |
| 38 |
writeLines(character(0L), con = empty) |
| 39 |
|
| 40 |
bfr <- readLines(empty) |
| 41 |
stopifnot(length(bfr) == 0) |
| 42 |
|
| 43 |
raw <- readRprofmem(empty, as = "raw") |
| 44 |
stopifnot(is.character(raw), length(raw) == 0) |
| 45 |
|
| 46 |
fixed <- readRprofmem(empty, as = "fixed") |
| 47 |
stopifnot(is.character(raw), length(raw) == 0) |
| 48 |
|
| 49 |
p <- readRprofmem(empty, as = "Rprofmem") |
| 50 |
stopifnot(nrow(p) == 0L) |
| 51 |
|
| 52 |
options(profmem.debug = FALSE) |
| 53 |
|
| 54 |
|
| 55 |
if (capabilities("profmem")) { |
| 56 |
|
| 57 |
live <- tempfile() |
| 58 |
Rprofmem(live) |
| 59 |
x <- raw(1000) |
| 60 |
A <- matrix(rnorm(100), ncol=10) |
| 61 |
Rprofmem() |
| 62 |
|
| 63 |
bfr <- readLines(live) |
| 64 |
cat("readLines(live):\n") |
| 65 |
print(bfr) |
| 66 |
|
| 67 |
raw <- readRprofmem(live, as = "raw") |
| 68 |
cat("readRprofmem(live, as = 'raw'):\n") |
| 69 |
print(raw) |
| 70 |
stopifnot( |
| 71 |
length(raw) == length(bfr), |
| 72 |
all(raw == bfr) |
| 73 |
) |
| 74 |
|
| 75 |
fixed <- readRprofmem(live, as = "fixed") |
| 76 |
cat("readRprofmem(live, as = 'fixed'):\n") |
| 77 |
print(fixed) |
| 78 |
stopifnot(length(fixed) >= length(bfr)) |
| 79 |
|
| 80 |
p <- readRprofmem(live, as = "Rprofmem") |
| 81 |
cat("readRprofmem(live, as = 'Rprofmem'):\n") |
| 82 |
print(p) |
| 83 |
str(p) |
| 84 |
stopifnot(nrow(p) == length(fixed)) |
| 85 |
|
| 86 |
} ## if (capabilities("profmem")) |
| 87 |
|
| 88 |
message("readRprofmem() ... DONE") |
| 89 |
|