-
Notifications
You must be signed in to change notification settings - Fork 186
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
Add S3 group generics to .base_s3_generics
, include exported S3 generics in generic list
#1842
Changes from 2 commits
d2222eb
79848fb
d843b63
25ea2ff
452c328
3c82281
d51c27a
f69b0f2
b16c2a4
aa44914
41ddeef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Parse namespace files and return imports exports, methods | ||
namespace_imports <- function(path = find_package()) { | ||
namespace_imports <- function(path = find_package(".")) { | ||
namespace_data <- tryCatch( | ||
parseNamespaceFile(basename(path), package.lib = file.path(path, "..")), | ||
error = function(e) NULL | ||
|
@@ -35,7 +35,7 @@ safe_get_exports <- function(ns) { | |
} | ||
|
||
empty_namespace_data <- function() { | ||
data.frame(pkg = character(), ns = character(), stringsAsFactors = FALSE) | ||
data.frame(pkg = character(), fun = character(), stringsAsFactors = FALSE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All other code paths return a data frame with column names |
||
} | ||
|
||
# filter namespace_imports() for S3 generics | ||
|
@@ -54,6 +54,22 @@ imported_s3_generics <- function(ns_imports) { | |
ns_imports[is_generic, ] | ||
} | ||
|
||
exported_s3_generics <- function(path = find_package(".")) { | ||
namespace_data <- tryCatch( | ||
parseNamespaceFile(basename(path), package.lib = file.path(path, "..")), | ||
error = function(e) NULL | ||
) | ||
|
||
if (length(namespace_data$S3methods) == 0L || nrow(namespace_data$S3methods) == 0L) { | ||
return(empty_namespace_data()) | ||
} | ||
|
||
data.frame( | ||
pkg = basename(path), | ||
fun = unique(namespace_data$S3methods[, 1L]) | ||
) | ||
} | ||
|
||
is_s3_generic <- function(fun) { | ||
# Inspired by `utils::isS3stdGeneric`, though it will detect functions that | ||
# have `useMethod()` in places other than the first expression. | ||
|
@@ -66,7 +82,7 @@ is_s3_generic <- function(fun) { | |
ret | ||
} | ||
|
||
.base_s3_generics <- c( | ||
.base_s3_generics <- unique(c( | ||
names(.knownS3Generics), | ||
.S3PrimitiveGenerics, | ||
if (getRversion() >= "3.5.0") { | ||
|
@@ -75,5 +91,16 @@ is_s3_generic <- function(fun) { | |
# R < 3.5.0 doesn't provide .S3_methods_table | ||
# fallback: search baseenv() for generic methods | ||
imported_s3_generics(data.frame(pkg = "base", fun = ls(baseenv()), stringsAsFactors = FALSE))$fun | ||
} | ||
) | ||
}, | ||
# S3 generic groups, see ?base::groupGeneric | ||
# Group "Math" | ||
c("abs", "sign", "sqrt", "floor", "ceiling", "trunc", "round", "signif", "exp", "log", "expm1", "log1p", "cos", | ||
AshesITR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"sin", "tan", "cospi", "sinpi", "tanpi", "acos", "asin", "atan", "cosh", "sinh", "tanh", "acosh", "asinh", "atanh", | ||
"lgamma", "gamma", "digamma", "trigamma", "cumsum", "cumprod", "cummax", "cummin"), | ||
# Group "Ops" | ||
c("+", "-", "*", "/", "^", "%%", "%/%", "&", "|", "!", "==", "!=", "<", "<=", ">=", ">"), | ||
# Group "Summary" | ||
c("all", "any", "sum", "prod", "min", "max", "range"), | ||
# Group "Complex" | ||
c("Arg", "Conj", "Im", "Mod", "Re") | ||
)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Package: clean | ||
Version: 0.0.1 | ||
RoxygenNote: 7.2.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
importFrom(utils,head) | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
S3method("names<-",my_custom_class) | ||
S3method(drink_me,data.frame) | ||
S3method(drink_me,default) | ||
S3method(drink_me,list) | ||
S3method(eat_me,liiiiiiiiiiiiiiiiiiiiiiiiiiist) | ||
S3method(head,my_s3_object) | ||
Comment on lines
+3
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are necessary for fixing #1808 |
||
export(drink_me) | ||
export(eat_me) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,10 @@ head.my_s3_object <- function(x, ...) { | |
`names<-.my_custom_class` <- function(x, value) { | ||
NULL | ||
} | ||
|
||
#' @export | ||
#' Defined S3 generic in R/eat_me.R | ||
#' Tests #1808 | ||
eat_me.liiiiiiiiiiiiiiiiiiiiiiiiiiist <- function(x, ...) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Class name has length 30, so this provokes |
||
NULL | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#' eat_me | ||
#' @description empty | ||
#' | ||
#' @export | ||
eat_me <- function(x, ...) { | ||
UseMethod("drink_me") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous default was an error.