Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ LazyData: true
RoxygenNote: 7.2.3
Imports:
shiny,
attempt
attempt,
R6,
qs,
fs
Suggests:
knitr,
rmarkdown,
Expand Down
95 changes: 95 additions & 0 deletions R/storage.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#' Storage object
#'
#' @importFrom R6 R6Class
#' @importFrom qs qsave qread
#' @importFrom fs path_norm dir_create path dir_delete file_delete
#' @export
Storage <- R6::R6Class(
"Storage",
public = list(
path = character(0),
initialize = function(
path = "~/.odds"
){
self$path <- path_norm(path)
dir_create(
self$path
)
},
set = function(
value,
object,
namespace = "global",
preset = "high",
algorithm = "zstd",
compress_level = 4L,
shuffle_control = 15L,
check_hash = TRUE,
nthreads = 1
){
dir_create(
path(
self$path,
namespace
)
)
qsave(
x = value,
file = path(
self$path,
namespace,
object,
ext = "qs"
),
preset = preset,
algorithm = algorithm,
compress_level = compress_level,
shuffle_control = shuffle_control,
check_hash = check_hash,
nthreads = nthreads
)
},
get = function(
value,
namespace = "global",
use_alt_rep = FALSE,
strict = FALSE,
nthreads = 1
){
qread(
file = path(
self$path,
namespace,
value,
ext = "qs"
),
use_alt_rep = use_alt_rep,
strict = strict,
nthreads = nthreads
)
},
rm = function(
value,
namespace = "global"
){
file_delete(
path(
self$path,
namespace,
value,
ext = "qs"
)
)
},
remove_namespace = function(
namespace
){
dir_delete(
path(
self$path,
namespace
)
)
}
)
)