On 2025-09-17 1:23 p.m., IVO I WELCH wrote:

Suggestion for Syntax Sugar:

Would it make sense to permit a simple way to allow a coder to document the 
function argument type?

f <- function( a:chr, b:data.frame, c:logi ) { … }

presumably, what comes behind the ‘:’ should match what ‘str’ returns.

however, this need not be checked (except perhaps when a particular option is 
set).  catching errors as soon as possible makes code easier to debug and error 
messages clearer.

We already have that: the Rd file should give a text description, and it can be enforced by run-time tests in the function body, e.g.

 stopifnot(is.char(a), is.data.frame(b), is.logical(c))

What we don't have, and I don't think it would be feasible, is a way to do this at compile time. In general variables and expressions in R don't have a fixed type that is known before they are evaluated.

Duncan Murdoch

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to