Skip to content

Commit

Permalink
refactor: move the check_ffeature function to another file (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi authored Nov 18, 2023
1 parent 91f21e1 commit 86721ea
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
31 changes: 0 additions & 31 deletions R/error_conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,34 +132,3 @@ raw_result = function(expr) {
}
)
}


#' Check Rust feature flag
#'
#' Raise error if the feature is not enabled
#' @noRd
#' @param feature_name name of feature to check
#' @inheritParams unwrap
#' @return TRUE invisibly if the feature is enabled
#' @keywords internal
#' @examples
#' tryCatch(
#' check_feature("simd", "in example"),
#' error = \(e) cat(as.character(e))
#' )
#' tryCatch(
#' check_feature("rpolars_debug_print", "in example"),
#' error = \(e) cat(as.character(e))
#' )
check_feature = function(feature_name, context = NULL, call = sys.call(1L)) {
if (!pl$polars_info()$features[[feature_name]]) {
Err_plain(
"\nFeature '", feature_name, "' is not enabled.\n",
"Please check the documentation about installation\n",
"and re-install with the feature enabled.\n"
) |>
unwrap(context, call)
}

invisible(TRUE)
}
30 changes: 30 additions & 0 deletions R/info.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,33 @@ print.polars_info = function(x, ...) {
cat("\n")
print_key_values("Features", unlist(x$features))
}

#' Check Rust feature flag
#'
#' Raise error if the feature is not enabled
#' @noRd
#' @param feature_name name of feature to check
#' @inheritParams unwrap
#' @return TRUE invisibly if the feature is enabled
#' @keywords internal
#' @examples
#' tryCatch(
#' check_feature("simd", "in example"),
#' error = \(e) cat(as.character(e))
#' )
#' tryCatch(
#' check_feature("rpolars_debug_print", "in example"),
#' error = \(e) cat(as.character(e))
#' )
check_feature = function(feature_name, context = NULL, call = sys.call(1L)) {
if (!pl$polars_info()$features[[feature_name]]) {
Err_plain(
"\nFeature '", feature_name, "' is not enabled.\n",
"Please check the documentation about installation\n",
"and re-install with the feature enabled.\n"
) |>
unwrap(context, call)
}

invisible(TRUE)
}

0 comments on commit 86721ea

Please sign in to comment.