Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve error message for functions needs feature flags #459

Merged
merged 5 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
34 changes: 34 additions & 0 deletions R/error_conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,37 @@ 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]]) {
paste0(
"\nFeature '", feature_name, "' is not enabled.\n",
"Please check the documentation about installation\n",
"and re-install with the the feature enabled.\n"
eitsupi marked this conversation as resolved.
Show resolved Hide resolved
) |>
where_in(context) |>
when_calling(call) |>
to_condition() |>
stop()
}

invisible(TRUE)
}
2 changes: 2 additions & 0 deletions R/expr__string.R
Original file line number Diff line number Diff line change
Expand Up @@ -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():")
}
Expand Down
2 changes: 2 additions & 0 deletions R/sql.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(...)

Expand Down
Loading