-
Notifications
You must be signed in to change notification settings - Fork 184
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
capture specifically generic names #755
Merged
Merged
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
aafe40a
capture specifically generic names
AshesITR cbc5270
add NEWS bullet
AshesITR a16b856
add regression test file
AshesITR 6e45d60
add anchors to regex
AshesITR 01e4e6d
add .lintr file to not exclude regression test file
AshesITR 58adea5
Merge branch 'master' into fix/737-generics-names
AshesITR 8de24a4
Merge branch 'master' into fix/737-generics-names
MichaelChirico 1d6ec7d
Merge branch 'master' into fix/737-generics-names
MichaelChirico e4fa911
improve generic detection
AshesITR 5485228
fix vapply
AshesITR 18ed390
Merge branch 'master' into fix/737-generics-names
AshesITR caa1bc0
make s3 detection more robust
AshesITR 5009392
backwards compatible base s3 generics
AshesITR 31b7687
try fixing compatibility issues with R 3.3 and 3.4
AshesITR ae61e37
typo
AshesITR d9247a8
fix R CMD check warning (by wrapping)
AshesITR 15ce499
remove dead code
AshesITR aa77625
de-lint
AshesITR 96d20ff
Merge branch 'master' into fix/737-generics-names
AshesITR 8da1f7b
Merge branch 'master' into fix/737-generics-names
AshesITR 9125b61
Merge branch 'master' into fix/737-generics-names
AshesITR 21c69ac
Merge branch 'master' into fix/737-generics-names
AshesITR 28eed9a
Merge branch 'master' into fix/737-generics-names
AshesITR fced525
Merge branch 'master' into fix/737-generics-names
AshesITR b6873f5
use nzchar
MichaelChirico 8d0233d
fix typo, improve style, fix compare_branches.R (forgot the fallback …
AshesITR fb0065e
Merge remote-tracking branch 'origin/fix/737-generics-names' into fix…
AshesITR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,43 @@ namespace_imports <- function(path = find_package()) { | |
data.frame( | ||
pkg = unlist(lapply(imports, function(x) rep(x[[1L]], length(x[[2L]])))), | ||
fun = unlist(lapply(imports, `[[`, 2L)), | ||
stringsAsFactors = FALSE) | ||
stringsAsFactors = FALSE | ||
) | ||
} | ||
|
||
# filter namespace_imports() for S3 generics | ||
# this loads all imported namespaces | ||
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. NB this already happens in |
||
imported_s3_generics <- function(ns_imports) { | ||
is_generic <- vapply( | ||
seq_len(nrow(ns_imports)), | ||
function(i) { | ||
fun_obj <- get(ns_imports$fun[i], envir = asNamespace(ns_imports$pkg[i])) | ||
MichaelChirico marked this conversation as resolved.
Show resolved
Hide resolved
|
||
is.function(fun_obj) && is_s3_generic(fun_obj) | ||
}, | ||
logical(1L) | ||
) | ||
|
||
ns_imports[is_generic, ] | ||
} | ||
|
||
is_s3_generic <- function(fun) { | ||
if (getRversion() >= "3.5.0") { | ||
# Available in 3.4.0, but bugged there in multiple ways that cause errors | ||
# throughout may base functions, e.g. `-`, `as.null.default`, `dontCheck` | ||
AshesITR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
utils::isS3stdGeneric(fun) | ||
} else { | ||
is.function(fun) # nocov | ||
} | ||
} | ||
|
||
.base_s3_generics <- c( | ||
names(.knownS3Generics), | ||
.S3PrimitiveGenerics, | ||
if (getRversion() >= "3.5.0") { | ||
.S3_methods_table[, 1L] | ||
} else { | ||
# 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 | ||
} | ||
) |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
exclusions: "R/default_linter_testcode.R" |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Regression test for #737 via expecting clean to be lint-free | ||
|
||
#' drink_me | ||
#' @description empty | ||
#' | ||
#' @export | ||
drink_me <- function(x, ...) { | ||
UseMethod("drink_me") | ||
} | ||
|
||
#' drink_me for most things | ||
#' @export | ||
drink_me.default <- function(x, ...) { | ||
1 | ||
} | ||
|
||
#' drink_me for lists | ||
#' @export | ||
drink_me.list <- function(x, ...) { | ||
NULL | ||
} | ||
|
||
#' drink_me for data.frames | ||
#' @export | ||
drink_me.data.frame <- function(x, ...) { | ||
NULL | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This was actually a false negative before.
row()
is a function inbase
, but not a generic, sorow.names
is not a generic method.Fun fact:
row.names()
is a generic sorow.names.x
would never lint.