I found another case of functions having another class : rlang::as_function
, when given, a formula argument, it returns a rlang_lambda_function
object. Unlike in magrittr
, the function
class is removed altogether. But I don't know if this is used by code or not.
You make a good point and it might be an XY problem, I mostly want structured documentation.
I think it's a bummer though that in a language where everything is a structured object, documentation is not at all. rdocumentation are in a unique position to be able to provide this but they don't seem to share my enthusiasm.
My question was general and largely out of curiosity but I'm also thinking a lot about adverbs these days, for example, how would you answer the following question :
What are the adverbs in base R ?
Negate()
is documented next to Reduce()
and Filter()
, the term adverb didn't exist, if I want to find such functions the only way I can think about is by running all the example of base packages, parsing them to see where there are simple calls of a given function returning a function, I could also check the Value field for the term "function" to get some candidates. That's messy!
An attribute for such type table functions would be handy in this case. I get your point about attributes existing for code, not to fix the doc however. But it CAN be used in code. If I use an adverb as the .f
parameter of map_chr
it could fail right away with an explicit message :
map_chr(c("foo","bar"), Negate)
#> Negate is an adverb and its output is not coercible to character, which map_chr requires
Instead I get
map_chr(c("foo","bar"), Negate)
#> Error in get(as.character(FUN), mode = "function", envir = envir) :
#> object 'foo' of mode 'function' was not found
The above operation will always fail, but the information I use to say that, though simple to define and objective, is not structured anywhere. Errors are right in the gray area between code and documentation, here we'd gain clearer errors AND ressources.