Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcdb7912

Browse files
authored
Dispatch namespaced call (#29)
* fix dispatch for namespaced calls* add news entry
1 parenta0b4c86 commitcdb7912

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

‎NEWS.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#sloop (development version)
22

3+
*`s3_dispatch()` now works for namespaced function calls (#25,@mgirlich).
4+
35
#sloop 1.0.1
46

57
* sloop has a website:http://sloop.r-lib.org/ !

‎R/dispatch.R‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ s3_dispatch <- function(call, env = parent.frame()) {
3737
if (!is_call(call)) {
3838
stop("`call` must be a function call",call.=FALSE)
3939
}
40-
generic<- as.character(call[[1]])
40+
41+
f<-call[[1]]
42+
if (is_call(f)) {
43+
n<- length(f)
44+
f<-f[[n]]
45+
}
46+
generic<- as.character(f)
4147
x<- eval(call[[2]],env)
4248

4349
class<- c(s3_class(x),"default")

‎tests/testthat/test-dispatch.R‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ test_that("includes internal generics", {
1616
expect_equal(out$method[[3]],"length (internal)")
1717
})
1818

19+
test_that("can handle namespaced function call", {
20+
out<- s3_dispatch(base::length(1))
21+
expect_length(out$method,4)
22+
expect_equal(out$method[[4]],"length (internal)")
23+
})
24+
1925
test_that("includes group generics", {
2026
out<- s3_dispatch(-Sys.Date())
2127
expect_equal(out$method, c("-.Date","-.default","Ops.Date","Ops.default","- (internal)"))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp