-
Notifications
You must be signed in to change notification settings - Fork 1
/
disk-part.r
77 lines (67 loc) · 1.8 KB
/
disk-part.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
source("part-api.r")
#######################################
# The disk.part specific function.
#######################################
# This will be a method that implements as_part.
as_disk_part <- function(x) {
ret <- list(file_path=file.path(options()$disk_part_dir, guid()))
con <- file(ret$file_path, open="wb", blocking=FALSE)
serialize(x, con)
close(con)
class(ret) <- c(class(ret), "disk.part")
ret
}
init_disk_part <- function(part_dir=tempdir()) {
# Create a new environment if it doesn't already exist.
options(disk_part_dir=part_dir)
options(default_part_constructor=as_disk_part)
TRUE
}
########################################
# The disk.part method definitions.
########################################
get_values.disk.part <- function(part, i, ...) {
con <- file(part$file_path, open="rb", blocking=FALSE)
x <- unserialize(con)
close(con)
if (!missing(i) && !missing(...)) {
x[i, ...]
} else if (missing(i) && !missing(...)) {
x[...]
} else if (!missing(i) && missing(...)) {
x[i]
} else {
x
}
}
get_attributes.disk.part <- function(part, labels) {
con <- file(part$file_path, open="rb", blocking=FALSE)
x <- unserialize(con)
close(con)
if (missing(labels)) {
attributes(x)
} else {
attributes(x)[[labels]]
}
}
get_object_size.disk.part <- function(part) {
con <- file(part$file_path, open="rb", blocking=FALSE)
x <- unserialize(con)
close(con)
object.size(x)
}
get_typeof.disk.part <- function(part) {
con <- file(part$file_path, open="rb", blocking=FALSE)
x <- unserialize(con)
close(con)
typeof(x)
}
get_class.disk.part <- function(part) {
con <- file(part$file_path, open="rb", blocking=FALSE)
x <- unserialize(con)
close(con)
class(x)
}
delete_part.disk.part <- function(part) {
file.remove(part$file_path)
}