-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#' @export | ||
store_class_format.nanoparquet <- function(format) { | ||
c("tar_nanoparquet", "tar_store") | ||
} | ||
|
||
#' @export | ||
store_assert_format_setting.nanoparquet <- function(format) { | ||
} | ||
|
||
#' @export | ||
store_read_path.tar_nanoparquet <- function(store, path) { | ||
object <- getNamespace("nanoparquet")[["read_parquet"]]( | ||
file = path, | ||
options = store_nanoparquet_options() | ||
) | ||
metadata <- getNamespace("nanoparquet")[["parquet_metadata"]](file = path) | ||
classes <- metadata$file_meta_data$key_value_metadata[[1L]] | ||
class(object) <- classes$value[classes$key == "class"] | ||
object | ||
} | ||
|
||
#' @export | ||
store_write_path.tar_nanoparquet <- function(store, object, path) { | ||
metadata <- class(object) | ||
names(metadata) <- rep("class", length(metadata)) | ||
getNamespace("nanoparquet")[["write_parquet"]]( | ||
x = object, | ||
file = path, | ||
metadata = metadata, | ||
compression = store$resources$nanoparquet[["compression"]], | ||
options = store_nanoparquet_options() | ||
) | ||
} | ||
|
||
#' @export | ||
store_assert_format.tar_nanoparquet <- function(store, object, name) { # nolint | ||
msg <- paste( | ||
"target", | ||
name, | ||
"has nanoparquet format, so it must be a data frame", | ||
"which can be converted to a tibble." | ||
) | ||
tar_assert_inherits( | ||
x = object %|||% data.frame(), | ||
class = "data.frame", | ||
msg = msg | ||
) | ||
} | ||
|
||
#' @export | ||
store_convert_object.tar_nanoparquet <- function(store, object) { | ||
if_any(is.null(object), as.data.frame(NULL), object) | ||
} | ||
|
||
#' @export | ||
store_get_packages.tar_nanoparquet <- function(store) { | ||
"nanoparquet" | ||
} | ||
|
||
store_nanoparquet_options <- function() { | ||
getNamespace("nanoparquet")[["parquet_options"]]( | ||
class = character(0L), | ||
use_arrow_metadata = TRUE, | ||
write_arrow_metadata = TRUE | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
resources_nanoparquet_init <- function( | ||
compression = "snappy" | ||
) { | ||
resources_nanoparquet_new( | ||
compression = compression | ||
) | ||
} | ||
|
||
resources_nanoparquet_new <- function( | ||
compression = NULL | ||
) { | ||
force(compression) | ||
enclass(environment(), c("tar_resources_nanoparquet", "tar_resources")) | ||
} | ||
|
||
#' @export | ||
resources_validate.tar_resources_nanoparquet <- function(resources) { | ||
tar_assert_scalar(resources$compression) | ||
tar_assert_chr(resources$compression) | ||
tar_assert_nzchar(resources$compression) | ||
} | ||
|
||
#' @export | ||
print.tar_resources_nanoparquet <- function(x, ...) { | ||
cat( | ||
"<tar_resources_nanoparquet>\n ", | ||
paste0(paste_list(as.list(x)), collapse = "\n ") | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#' @title Target resources: nanoparquet storage format | ||
#' @export | ||
#' @family resources | ||
#' @description Create the nanoparquet argument of `tar_resources()` | ||
#' to specify optional settings for nanoparquet data frame storage formats | ||
#' powered by the `nanoparquet` R package. | ||
#' See the `format` argument of [tar_target()] for details. | ||
#' @inheritSection tar_resources Resources | ||
#' @return Object of class `"tar_resources_nanoparquet"`, to be supplied | ||
#' to the nanoparquet argument of `tar_resources()`. | ||
#' @param compression Character of length 1, `compression` | ||
#' argument of `nanoparquet::write_parquet()`. Defaults to `"snappy"`. | ||
#' @examples | ||
#' # Somewhere in you target script file (usually _targets.R): | ||
#' tar_target( | ||
#' name, | ||
#' command(), | ||
#' format = "nanoparquet", | ||
#' resources = tar_resources( | ||
#' nanoparquet = tar_resources_nanoparquet(compression = "zstd") | ||
#' ) | ||
#' ) | ||
tar_resources_nanoparquet <- function( | ||
compression = targets::tar_option_get("resources")$nanoparquet$compression | ||
) { | ||
compression <- compression %|||% "snappy" | ||
out <- resources_nanoparquet_init( | ||
compression = compression | ||
) | ||
resources_validate(out) | ||
out | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.