-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e8b37e
commit a577aa0
Showing
6 changed files
with
130 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#' Internal functions for working with the fst cache | ||
#' @name fst-utils | ||
#' @noRd | ||
#' | ||
#' @param cat_no,path As in \code{\link{read_abs}}. | ||
#' | ||
#' @return For `catno2fst` the path to the `fst` file to be saved or read, given | ||
#' `cat_no` and `path`. | ||
#' | ||
#' `fst_available` returns `TRUE` if and only if an appropriate `fst` file is | ||
#' available. | ||
#' | ||
#' `ext2ext` changes the extension of the provided file to a file in the same | ||
#' path but with the provided extension. | ||
#' | ||
|
||
|
||
catno2fst <- function(cat_no, | ||
path = Sys.getenv("R_READABS_PATH", unset = tempdir())) { | ||
hutils::provide.file(file.path(path, | ||
"fst", | ||
paste0(gsub(".", "-", cat_no, fixed = TRUE), | ||
".fst")), | ||
on_failure = stop("`path = ", normalizePath(path, winslash = "/"), "`, ", | ||
"but it was not possible to write to this directory.")) | ||
} | ||
|
||
fst_available <- function(cat_no, | ||
path = Sys.getenv("R_READABS_PATH", unset = tempdir())) { | ||
if (!requireNamespace("fst", quietly = TRUE) || | ||
!dir.exists(path)) { | ||
return(FALSE) | ||
} | ||
|
||
file.fst <- catno2fst(cat_no, path) | ||
|
||
if (!file.exists(file.fst)) { | ||
return(FALSE) | ||
} | ||
|
||
# fst may be damaged. If it appears to be (i.e. fst metadata returns an error) | ||
# return FALSE | ||
|
||
# nocov start | ||
out <- tryCatch(inherits(fst::fst.metadata(file.fst), "fstmetadata"), | ||
error = function(e) FALSE, | ||
warning = function(e) FALSE) | ||
# nocov end | ||
out | ||
} | ||
|
||
ext2ext <- function(file, new.ext) { | ||
paste0(tools::file_path_sans_ext(file), new.ext) | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.