-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: switch from extendr to the savvy framework (#252)
This is a proof of concept of migration from the extendr framework to the savvy framework. The bonus is that you can compile the package for webR. But, there are some caveats. * savvy doesn't provide the default argument. You need to write a wrapper manually. * savvy doesn't support `Option` as the argument, so you have to handle it on R's side. --------- Co-authored-by: eitsupi <[email protected]>
- Loading branch information
1 parent
0756505
commit 2b00b41
Showing
25 changed files
with
284 additions
and
261 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
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
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 |
---|---|---|
@@ -1,50 +1 @@ | ||
#' @title Rust-like unwrapping of result. Useful to do error handling on the R side. | ||
#' @param result a list where either element ok or err is NULL, or both if ok is a literal NULL. | ||
#' @param call context of error or string used for error printing, could be omitted. | ||
#' @return the ok-element of list , or a error will be thrown | ||
#' @examples | ||
#' # export unwrap for this example, only for internal use | ||
#' unwrap <- prqlr:::unwrap | ||
#' | ||
#' # unwrap a result with the ok-value "foo" | ||
#' unwrap(list(ok = "foo", err = NULL)) | ||
#' | ||
#' # unwrap an err-result | ||
#' tryCatch( | ||
#' unwrap(ok = NULL, err = "something happend on the rust side"), | ||
#' error = function(e) as.character(e) | ||
#' ) | ||
#' @noRd | ||
unwrap <- function(result, call = sys.call(1L)) { | ||
# if not result | ||
if (!inherits(result, "rust_result") && (!is.list(result) || !all(names(result) %in% c("ok", "err")))) { | ||
stop("Internal error: cannot unwrap non result") | ||
} | ||
|
||
# if result is ok (ok can be be valid null, hence OK if both ok and err is null) | ||
if (is.null(result$err)) { | ||
return(result$ok) | ||
} | ||
|
||
# if result is error, raise R errors. Modify the error formatting as necessary. | ||
if (is.null(result$ok) && !is.null(result$err)) { | ||
stop(result$err) | ||
|
||
# add some custom error context, or just delete | ||
# stop( | ||
# paste( | ||
# result$err, | ||
# paste( | ||
# "\nwhen calling:\n", | ||
# paste( | ||
# capture.output(print(call)),collapse="\n") | ||
# ) | ||
# ) | ||
# ) | ||
} | ||
|
||
# if not ok XOR error, then it must be another internal error. | ||
stop("Internal error: result object corrupted") | ||
} | ||
|
||
`%||%` <- function(x, y) if (is.null(x)) y else x |
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
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
Oops, something went wrong.