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

ARROW-13886 [R] Expand documentation for decimal() #11758

Closed
wants to merge 11 commits into from
13 changes: 11 additions & 2 deletions r/R/type.R
Expand Up @@ -187,8 +187,11 @@ NestedType <- R6Class("NestedType", inherit = DataType)
#' @param timezone For `timestamp()`, an optional time zone string.
#' @param byte_width byte width for `FixedSizeBinary` type.
#' @param list_size list size for `FixedSizeList` type.
#' @param precision For `decimal()`, precision
#' @param scale For `decimal()`, scale
#' @param precision For `decimal()`, precision. The number of significant digits
dragosmg marked this conversation as resolved.
Show resolved Hide resolved
#' the arrow `decimal` type can represent. Currently `decimal()` is mapped
#' to `DecimalType128`, having a maximum precision of 38 significant digits.
dragosmg marked this conversation as resolved.
Show resolved Hide resolved
#' @param scale For `decimal()`, scale. The number of digits after the decimal
dragosmg marked this conversation as resolved.
Show resolved Hide resolved
#' point. It can be negative.
dragosmg marked this conversation as resolved.
Show resolved Hide resolved
#' @param type For `list_of()`, a data type to make a list-of-type
#' @param ... For `struct()`, a named list of types to define the struct columns
#'
Expand Down Expand Up @@ -360,6 +363,12 @@ decimal <- function(precision, scale) {
} else {
stop('"precision" must be an integer', call. = FALSE)
}
if (precision > 38) {
stop('"precision" must be lower than or equal to 38', call. = FALSE)
dragosmg marked this conversation as resolved.
Show resolved Hide resolved
}
if (precision < 1) {
stop('"precision" must be greater than 0', call. = FALSE)
}
dragosmg marked this conversation as resolved.
Show resolved Hide resolved
if (is.numeric(scale)) {
scale <- as.integer(scale)
} else {
Expand Down
7 changes: 5 additions & 2 deletions r/man/data-type.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions r/tests/testthat/test-data-type.R
Expand Up @@ -390,8 +390,8 @@ test_that("decimal type and validation", {
expect_error(decimal(4))
expect_error(decimal(4, "two"), '"scale" must be an integer')
expect_error(decimal(NA, 2), '"precision" must be an integer')
expect_error(decimal(0, 2), "Invalid: Decimal precision out of range: 0")
expect_error(decimal(100, 2), "Invalid: Decimal precision out of range: 100")
expect_error(decimal(0, 2), "\"precision\" must be greater than 0")
expect_error(decimal(100, 2), "\"precision\" must be lower than or equal to 38")
dragosmg marked this conversation as resolved.
Show resolved Hide resolved
expect_error(decimal(4, NA), '"scale" must be an integer')

expect_r6_class(decimal(4, 2), "Decimal128Type")
Expand Down