stan-dev / posterior

The posterior R package
https://mc-stan.org/posterior/
Other
167 stars 24 forks source link

rfun does not work with primitive functions #290

Closed ksvanhorn closed 1 year ago

ksvanhorn commented 1 year ago

Package version: posterior 1.3.1 R version: 4.2.2 Platform: macOS 13.4 (Ventura)

Example:

posterior::rfun(sin)(posterior::rvar(1:10))

This gives the error message "unused argument (posterior::rvar(1:10))"; furthermore,

posterior::rfun(sin)

reveals that the generated function has no arguments. I only see this problem with primitive functions.

mjskay commented 1 year ago

Thanks! I see the problem with how primitive versus normal functions handle argument lists and have prepared a fix.

Minor note re: sin specifically: since it is a member of the Math group of functions it has an implementation for the rvar class. You can and should use it directly on an rvar as it will be much faster than using rfun(sin).