diff --git a/R/error_conversion.R b/R/error_conversion.R index e03b973f3..940dba05a 100644 --- a/R/error_conversion.R +++ b/R/error_conversion.R @@ -132,3 +132,34 @@ 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) +} diff --git a/R/expr__string.R b/R/expr__string.R index f4770a2b9..f1690b77b 100644 --- a/R/expr__string.R +++ b/R/expr__string.R @@ -188,6 +188,8 @@ ExprStr_to_lowercase = function() { #' tryCatch(f(), error = as.character) #' } ExprStr_to_titlecase = function() { + check_feature("full_features", "in $to_titlecase():") + .pr$Expr$str_to_titlecase(self) |> unwrap("in $to_titlecase():") } diff --git a/R/sql.R b/R/sql.R index b532aa85b..3f1f1ac54 100644 --- a/R/sql.R +++ b/R/sql.R @@ -36,6 +36,8 @@ RPolarsSQLContext #' ctx = pl$SQLContext(mtcars = mtcars) #' ctx pl$SQLContext = function(...) { + check_feature("sql", "in $SQLContext()") + self = .pr$RPolarsSQLContext$new() lazyframes = list(...)