R devtools::check() WARNING: “The argument of a replacement function which corresponds to the right hand side must be named ‘value’.”

I am using devtools::check() in R to check a package and cannot overcome this warning:

The argument of a replacement function which corresponds to the right
hand side must be named ‘value’.

You can see below in the example code that I do indeed have value as the RHS argument for the function. Other replacement functions in the same package do not throw this warning. What am I doing wrong?

methods::setGeneric(name = "addTable<-", def = function(x, value, ...) standardGeneric("addTable<-"))

#' MyClass
#'
#' @aliases MyClass
#' @rdname MyClass
#' @exportClass MyClass
MyClass <- methods::setClass(
    Class = "MyClass",
    slots = list(
        table = "data.frame"
    ),
    prototype = prototype(
        table = data.frame()
    )
)

#' Attach a data frame to a MyClass object
#'
#' @description `addTable()` adds a table to a `MyClass` object.
#'
#' @param x A `MyClass`.
#' @param value A `data.frame`.
#'
#' @returns A `MyClass` object.
#'
#' @aliases addTable<-
#' @rdname addTable
#' @exportMethod addTable<-
methods::setMethod(
    f = "addTable<-",
    signature = c(x = "MyClass", value = "data.frame"),
    function(x, value) {
    
    x@table <- value
    x
    
    }
)

Upon devtools::check(), this returns the warning:

checking replacement functions … WARNING
‘addTable<-‘ ‘S4method{addTable<-}{MyClass,data.frame}’
The argument of a replacement function which corresponds to the right
hand side must be named ‘value’.

I’ve tried:

  • Making a test package that has just the offending method and only the methods package as a dependency and no other classes or methods (i.e., this example)
  • Using the tag @aliases addTable<-,MyClass,data.frame-method
  • Renaming x to object
  • Swapping the position of x and value in the signature and definition part of the method definition (plus setGeneric)… which is different from any other replacement function I’ve seen, but I gotta try something

Obviously, I’m just casting rocks in an ocean and hoping to hit a fish.

I’m running R 4.4.0 and RTools 4.4.

4

S4 Setter Functions

For S4 setters, the “value” argument must be the last argument in the function definition. Most of the time, setters in the wild have two arguments, the object and the new value like below:

## toy class
methods::setClass("Numbers", slots = c(number = "numeric"))

## create a setter generic
methods::setGeneric("number<-", function(x, value) standardGeneric("number<-"))

## create a method for `Numbers` class
methods::setMethod("number<-", "Numbers", function(x, value) {
  x@number <- value
  x
})

## instantiate a `Numbers` object
obj <- new("Numbers", number = 5)
obj

# An object of class "Numbers"
# Slot "number":
# [1] 5

## usage
number(obj) <- 3
obj

# An object of class "Numbers"
# Slot "number":
# [1] 3

## alternate usage - no assignment
`number<-`(obj, 1)

# An object of class "Numbers"
# Slot "number":
# [1] 1

obj

# An object of class "Numbers"
# Slot "number":
# [1] 3

## alternate usage - requires assignment
obj <- `number<-`(obj, 1)
obj

# An object of class "Numbers"
# Slot "number":
# [1] 1

If you want to add additional arguments to the setter, they must be included before the “value” argument either as named arguments or ellipsis like so:

methods::setGeneric("fancy_number<-", function(x, ..., value) standardGeneric("fancy_number<-"))

These additional arguments can be used to modify how the values are assigned.

methods::setMethod("fancy_number<-", "Numbers", function(x, operation = c("add", "replace"), value) {
  if (operation == "add") {
    x@number <- x@number + value 
  } else if (operation == "replace") {
    number(x) <- value
  }
  x
})

## usage - note position of new arguments on left of arrow
fancy_number(obj, "add") <- 100
obj

# An object of class "Numbers"
# Slot "number":
# [1] 101

fancy_number(obj, "replace") <- 7
obj

# An object of class "Numbers"
# Slot "number":
# [1] 7

This is probably why “value” must be the last argument – R needs to know what one value is being assigned.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật