Skip to content

Commit

Permalink
Merge pull request #463 from RConsortium/revert-implicit-s3-array
Browse files Browse the repository at this point in the history
revert `class_array` and `class_matrix`
  • Loading branch information
t-kalinowski authored Oct 15, 2024
2 parents 2545729 + f1073a2 commit 4c3cb81
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 52 deletions.
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export(class_POSIXct)
export(class_POSIXlt)
export(class_POSIXt)
export(class_any)
export(class_array)
export(class_atomic)
export(class_call)
export(class_character)
Expand All @@ -65,7 +64,6 @@ export(class_integer)
export(class_language)
export(class_list)
export(class_logical)
export(class_matrix)
export(class_missing)
export(class_name)
export(class_numeric)
Expand Down
20 changes: 10 additions & 10 deletions R/S3.R
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ validate_formula <- function(self) {
#' * `class_Date` for dates.
#' * `class_factor` for factors.
#' * `class_POSIXct`, `class_POSIXlt` and `class_POSIXt` for date-times.
#' * `class_matrix` for matrices.
#' * `class_array` for arrays.
# * `class_matrix` for matrices.
# * `class_array` for arrays.
#' * `class_formula` for formulas.

#'
Expand Down Expand Up @@ -325,10 +325,10 @@ class_data.frame <- new_S3_class("data.frame",
validator = validate_data.frame
)

#' @export
#' @rdname base_s3_classes
#' @format NULL
#' @order 3
# @export
# @rdname base_s3_classes
# @format NULL
# @order 3
class_matrix <- new_S3_class("matrix",
constructor = function(.data = logical(), nrow = NULL, ncol = NULL, byrow = FALSE, dimnames = NULL) {
nrow <- nrow %||% NROW(.data)
Expand All @@ -343,10 +343,10 @@ class_matrix <- new_S3_class("matrix",
validator = validate_matrix
)

#' @export
#' @rdname base_s3_classes
#' @format NULL
#' @order 3
# @export
# @rdname base_s3_classes
# @format NULL
# @order 3
class_array <- new_S3_class("array",
constructor = function(.data = logical(),
dim = base::dim(.data) %||% length(.data),
Expand Down
4 changes: 2 additions & 2 deletions R/S4.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ S4_basic_classes <- function() {
POSIXct = class_POSIXct,
POSIXlt = class_POSIXlt,
POSIXt = class_POSIXt,
matrix = class_matrix,
array = class_array,
# matrix = class_matrix,
# array = class_array,
formula = class_formula
)
}
Expand Down
8 changes: 0 additions & 8 deletions man/base_s3_classes.Rd

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

60 changes: 30 additions & 30 deletions tests/testthat/test-base.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,25 +250,25 @@ test_that("Base S3 classes can be parents", {
expect_error(Foo(list(x = 1:3, y = 1:4)),
"all variables should have the same length")

expect_no_error({
Foo := new_class(class_matrix)
Foo(1:4, nrow = 2)
Foo(NA)
Foo(matrix(1:4, nrow = 2))
})

expect_no_error({
Foo := new_class(class_array)

Foo(array(1:4, dim = c(2, 2)))
Foo(1:4, dim = c(2, 2))

Foo(array(1:24, dim = c(2, 3, 4)))
Foo(1:24, dim = c(2, 3, 4))

Foo(array(1))
Foo(1)
})
# expect_no_error({
# Foo := new_class(class_matrix)
# Foo(1:4, nrow = 2)
# Foo(NA)
# Foo(matrix(1:4, nrow = 2))
# })

# expect_no_error({
# Foo := new_class(class_array)
#
# Foo(array(1:4, dim = c(2, 2)))
# Foo(1:4, dim = c(2, 2))
#
# Foo(array(1:24, dim = c(2, 3, 4)))
# Foo(1:24, dim = c(2, 3, 4))
#
# Foo(array(1))
# Foo(1)
# })

expect_no_error({
Foo := new_class(class_formula)
Expand All @@ -294,17 +294,17 @@ test_that("Base S3 classes can be properties", {
})
expect_error(Foo(x = 1), "@x must be S3<data.frame>, not <double>")

expect_no_error({
Foo := new_class(properties = list(x = class_matrix))
Foo(x = matrix())
})
expect_error(Foo(x = 1), "@x must be S3<matrix>, not <double>")

expect_no_error({
Foo := new_class(properties = list(x = class_array))
Foo(x = array())
})
expect_error(Foo(x = 1), "@x must be S3<array>, not <double>")
# expect_no_error({
# Foo := new_class(properties = list(x = class_matrix))
# Foo(x = matrix())
# })
# expect_error(Foo(x = 1), "@x must be S3<matrix>, not <double>")

# expect_no_error({
# Foo := new_class(properties = list(x = class_array))
# Foo(x = array())
# })
# expect_error(Foo(x = 1), "@x must be S3<array>, not <double>")

expect_no_error({
Foo := new_class(properties = list(x = class_formula))
Expand Down

0 comments on commit 4c3cb81

Please sign in to comment.