-
Notifications
You must be signed in to change notification settings - Fork 37
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
properties not passed to constructor signature cause R CMD check to raise a warning #304
Comments
Since |
this is definitely not what I intended, as the @param should document the properties of the S7 class object, but not the constructor interface. My point is, the R CMD check should either check the properties field, or the new_object() function argument in the constructor, but not the argument of constructor interface. for example, if I am implementing an optimizer class, some of the config variable would be know in advance and can be passed to the constructor interface, but the 'optimal solution' property would not be known at the time the object is initialized, it is only known after calling some generic function 'optimize' to set the field 'optimal solution'. but the format of the 'optimal solution' should be documented anyway for any downstream task which is using it. it is very unintuitive to have the 2 cases: case 1: #' @import S7
#' @title test class
#' @description test class
#' @param x numeric
#' @param y numeric
#' @param z character
#' @export
test_class <- new_class("test_class",
properties = list(
x = class_numeric,
y = class_numeric,
z = class_character
)
) where it calls some default constructor, and since R CMD check doesn't complain about it, people would expect that the '@param' are used to document the properties, not the constructor interface. case 2: #' @import S7
#' @title test class
#' @description test class
#' @param x numeric
#' @param y numeric
#' @param z character
#' @export
test_class <- new_class("test_class",
properties = list(
x = class_numeric,
y = class_numeric,
z = class_character
),
constructor = function(x, y) {
new_object(
NULL,
x = x,
y = y,
z = character(0)
)
}
) now R CMD check complains about the documentations, and seems it assume that the documentation is about the constructor, but that wouldn't be what users assumes, since from case 1 they would generally assume the documentation is about properties. it confuses people. |
If this is mainly about Roxygen --> *.Rd translation, then Roxygen should be fixed, but I don't think that's the case here. Rather I guess the code analysis that Relatedly, why are you not using proper indentation in your example? OTOH, R's Rd-syntax does know about S4 syntax for class and method definitions, and maybe we can Alternatively: "We" should find out where in R (or the |
The library(S7)
test_class <- new_class("test_class",
properties = list(
x = class_numeric,
y = class_numeric,
z = class_character
),
constructor = function(x, y) {
new_object(
NULL,
x = x,
y = y,
z = character(0)
)
}
)
args(test_class)
#> function (x, y)
#> NULL And So I'm pretty sure the current behaviour is correct. |
@mmaechler the lack of indentation was because the incorrect markdown for code blocks was used; I've fixed that. |
the S4 way to document the object is consistent and doesn't raise a warning:
The confusing part is if you just document the slot using
This is originally why I assume the |
I think you are confused by the current lack of support for S7 in roxygen2. That issue is tracked at r-lib/roxygen2#1484. |
I see the following code to result in a warning in R CMD check:
this causes a warning in R CMD check:
seems the check thinks the variable z is not used in the constructor function thus it is redundant.
a way to bypass the warning is to pass 'z' to the constructor as well:
this time R CMD check doesn't complain about it. I feel this should either be documented as best practice to implement a constructor or having R CMD check to be smart about the actual intension about this interface.
The text was updated successfully, but these errors were encountered: