diff --git a/NEWS.md b/NEWS.md index 7300b060..99d93d41 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # roxygen2 (development version) +* roxygen2 now recognises the walrus operator `:=` as assignment, so S7 code like `Foo := new_class()` is documented the same as `Foo <- new_class()` (#1916). * `@inherit` and friends once again find external topics whose name needs backticks, like ``pkg::`foo-class` `` (@taekop, #1918). * `@inherit foo returns` now inherits the return value, like `@inherit foo return`, instead of warning about an unknown type (@taekop, #1919). diff --git a/R/object-from-call.R b/R/object-from-call.R index e0714407..aa4b46af 100644 --- a/R/object-from-call.R +++ b/R/object-from-call.R @@ -18,7 +18,8 @@ object_from_call <- function(call, env, block, file) { name, "=" = , "<-" = , - "<<-" = parser_assignment(call, env, block), + "<<-" = , + ":=" = parser_assignment(call, env, block), "delayedAssign" = parser_delayedAssign(call, env, block), "::" = parser_import(call, env, block), diff --git a/tests/testthat/test-object-from-call.R b/tests/testthat/test-object-from-call.R index 060f4665..b62b06b4 100644 --- a/tests/testthat/test-object-from-call.R +++ b/tests/testthat/test-object-from-call.R @@ -70,6 +70,17 @@ test_that("finds function created with assignment", { expect_s3_class(obj, "function") }) +test_that("finds function created with walrus assignment", { + obj <- call_to_object({ + `:=` <- function(x, y) { + assign(deparse(substitute(x)), y, envir = parent.frame()) + } + foo := function(x, y, z) {} + }) + expect_s3_class(obj, "function") + expect_equal(obj$alias, "foo") +}) + test_that("finds S3 generic created with assignment", { obj <- call_to_object({ foo <- function(x, y, z) UseMethod("foo")