-
Notifications
You must be signed in to change notification settings - Fork 3
/
hoard.Rd
162 lines (148 loc) · 4.58 KB
/
hoard.Rd
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/hoard_client.R
\name{hoard}
\alias{hoard}
\title{hoardr class}
\arguments{
\item{path}{(character) a path to cache files in. required}
\item{type}{(character) type of cache. One of "user_cache_dir" (default),
"user_log_dir", "user_data_dir", "user_config_dir", "site_data_dir",
"site_config_dir". Can also pass in any function that gives a path to a
directory, e.g., \code{tempdir()}. required.}
}
\description{
hoardr class
}
\details{
For the purposes of caching, you'll likely want to stick with
\code{user_cache_dir}, but you can change the type of cache with the \code{type}
parameter.
\code{hoard} is just a tiny wrapper around \code{HoardClient$new()}, which isn't
itself exported, but you can use it if you want via \code{:::}
\strong{Methods}
\describe{
\item{\code{cache_path_get()}}{
Get the cache path
\strong{return}: (character) path to the cache directory
}
\item{\code{cache_path_set(path = NULL, type = "user_cache_dir", prefix = "R", full_path = NULL)}}{
Set the cache path. By default, we set cache path to
\code{file.path(user_cache_dir, prefix, path)}. Note that this does not
actually make the directory, but just sets the path to it.
\itemize{
\item path (character) the path to be appended to the cache path set
by \code{type}
\item type (character) the type of cache, see \link{rappdirs}
\item prefix (character) prefix to the \code{path} value. Default: "R"
\item full_path (character) instead of using \code{path}, \code{type}, and \code{prefix}
just set the full path with this parameter
}
\strong{return}: (character) path to the cache directory just set
}
\item{\code{list()}}{
List files in the directory (full file paths)
\strong{return}: (character) vector of file paths for files in the cache
}
\item{\code{mkdir()}}{
Make the directory if doesn't exist already
\strong{return}: \code{TRUE}, invisibly
}
\item{\code{delete(files, force = TRUE)}}{
Delete files by name
\itemize{
\item files (character) vector/list of file paths
\item force (logical) force deletion? Default: \code{TRUE}
}
\strong{return}: nothing
}
\item{\code{delete_all(force = TRUE)}}{
Delete all files
\itemize{
\item force (logical) force deletion? Default: \code{FALSE}
}
\strong{return}: nothing
}
\item{\code{details(files = NULL)}}{
Get file details
\itemize{
\item files (character) vector/list of file paths
}
\strong{return}: objects of class \code{cache_info}, each with brief summary
info including file path and file size
}
\item{\code{keys(algo = "md5")}}{
Get a hash for all files. Note that these keys may not be unique
if the files are identical, leading to identical hashes
\strong{return}: (character) hashes for the files
}
\item{\code{key(x, algo = "md5")}}{
Get a hash for a single file. Note that these keys may not be unique
if the files are identical, leading to identical hashes
\itemize{
\item x (character) path to a file
\item algo (character) the algorithm to be used, passed on to
\code{\link[digest:digest]{digest::digest()}}, choices: md5 (default), sha1, crc32, sha256,
sha512, xxhash32, xxhash64 and murmur32.
}
\strong{return}: (character) hash for the file
}
\item{\code{files()}}{
Get all files as HoardFile objects
\strong{return}: (character) paths to the files
}
\item{\code{compress()}}{
Compress files into a zip file - leaving only the zip file
\strong{return}: (character) path to the cache directory
}
\item{\code{uncompress()}}{
Uncompress all files and remove zip file
\strong{return}: (character) path to the cache directory
}
}
}
\examples{
(x <- hoard())
x$cache_path_set(path = "foobar", type = 'tempdir')
x
x$path
x$cache_path_get()
# Or you can set the full path directly with `full_path`
mydir <- file.path(tempdir(), "foobar")
x$cache_path_set(full_path = mydir)
x
x$path
x$cache_path_get()
# make the directory if doesn't exist already
x$mkdir()
# list files in dir
x$list()
cat(1:10000L, file = file.path(x$cache_path_get(), "foo.txt"))
x$list()
# cache details
x$details()
# delete files by name - we prepend the base path for you
x$delete("foo.txt")
x$list()
x$details()
# delete all files
cat("one\\ntwo\\nthree", file = file.path(x$cache_path_get(), "foo.txt"))
cat("asdfasdf asd fasdf", file = file.path(x$cache_path_get(), "bar.txt"))
x$delete_all()
x$list()
# make/get a key for a file
cat(1:10000L, file = file.path(x$cache_path_get(), "foo.txt"))
x$keys()
x$key(x$list()[1])
# as files
Map(function(z) z$exists(), x$files())
# compress and uncompress
x$compress()
x$uncompress()
# reset cache path
x$cache_path_set(path = "stuffthings", type = "tempdir")
x
x$cache_path_get()
x$list()
# cleanup
unlink(x$cache_path_get())
}