From 63453f30f144791a440743abb3b0cffb2c6c456f Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 2 Oct 2026 08:16:42 -0400 Subject: [PATCH] Recognise `:=` as assignment S7's walrus operator now documents the same as `<-`, e.g. `Foo := new_class()` generates full Rd including usage. Fixes #1916. --- NEWS.md | 1 + R/object-from-call.R | 3 ++- tests/testthat/test-object-from-call.R | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 7300b0609..99d93d41e 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 e0714407e..aa4b46aff 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 060f46657..b62b06b48 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")