This function helps to map between R functions and Stan functions.

lookup(FUN, ReturnType = character())

Arguments

FUN

A character string naming a R function or a R function for which the (near) equivalent Stan function is sought. If no matching R function is found, FUN is reinterpreted as a regexp and matches are sought.

ReturnType

A character string of positive length naming a valid return type for a Stan function: int, int[], matrix, real, real[,], real[], row_vector, T[], vector, or void. If "ANY" is passed, then the entire data.frame is returned and can be inspected with the View function, for example.

Value

Ordinarily, a data.frame with rows equal to the number of partial matches and four columns:

  1. StanFunction Character string for the Stan function's name.

  2. Arguments Character string indicating the arguments to that Stan function.

  3. ReturnType Character string indicating the return type of that Stan function.

  4. Page Integer indicating the page of the Stan reference manual where that Stan function is defined.

If there are no matching Stan functions, a character string indicating so is returned.

References

The Stan Development Team Stan Modeling Language User's Guide and Reference Manual. https://mc-stan.org/.

The Stan Development Team CmdStan Interface User's Guide. https://mc-stan.org.

Examples

lookup(dnorm)      # Stan equivalents for the normal PDF (in log form)
#>           StanFunction
#> 374 normal_id_glm_lpmf
#> 375 normal_id_glm_lpmf
#> 376      normal_id_glm
#> 379        normal_lpdf
#> 380             normal
#>                                                        Arguments ReturnType
#> 374   (vector y , matrix x, real alpha, vector beta, real sigma)       real
#> 375 (vector y , matrix x, vector alpha, vector beta, real sigma)       real
#> 376                                                            ~       real
#> 379                            (reals y , reals mu, reals sigma)       real
#> 380                                                            ~       real
lookup("foo")      # fails
#> [1] "no matching Stan functions"
lookup("Student")  # succeeds even though there is no such R function
#>             StanFunction
#> 345 multi_student_t_lpdf
#> 346 multi_student_t_lpdf
#> 347 multi_student_t_lpdf
#> 348 multi_student_t_lpdf
#> 349      multi_student_t
#> 350  multi_student_t_rng
#> 351  multi_student_t_rng
#> 352  multi_student_t_rng
#> 353  multi_student_t_rng
#> 644        student_t_cdf
#> 645      student_t_lccdf
#> 646       student_t_lcdf
#> 647       student_t_lpdf
#> 648            student_t
#> 649        student_t_rng
#>                                                   Arguments ReturnType
#> 345 (row_vectors y , real nu, row_vectors mu, matrix Sigma)       real
#> 346     (row_vectors y , real nu, vectors mu, matrix Sigma)       real
#> 347     (vectors y , real nu, row_vectors mu, matrix Sigma)       real
#> 348         (vectors y , real nu, vectors mu, matrix Sigma)       real
#> 349                                                       ~       real
#> 350                  (real nu, row_vector mu, matrix Sigma)     vector
#> 351                 (real nu, row_vectors mu, matrix Sigma)    vectors
#> 352                      (real nu, vector mu, matrix Sigma)     vector
#> 353                     (real nu, vectors mu, matrix Sigma)    vectors
#> 644              (reals y, reals nu, reals mu, reals sigma)       real
#> 645             (reals y , reals nu, reals mu, reals sigma)       real
#> 646             (reals y , reals nu, reals mu, reals sigma)       real
#> 647             (reals y , reals nu, reals mu, reals sigma)       real
#> 648                                                       ~       real
#> 649                       (reals nu, reals mu, reals sigma)          R
lookup("^poisson") # every Stan function that starts with poisson
#>             StanFunction                                       Arguments
#> 532          poisson_cdf                          (ints n, reals lambda)
#> 533        poisson_lccdf                         (ints n , reals lambda)
#> 534         poisson_lcdf                         (ints n , reals lambda)
#> 535 poisson_log_glm_lpmf   (int[] y , matrix x, real alpha, vector beta)
#> 536 poisson_log_glm_lpmf (int[] y , matrix x, vector alpha, vector beta)
#> 537      poisson_log_glm                                               ~
#> 538     poisson_log_lpmf                          (ints n , reals alpha)
#> 539          poisson_log                                               ~
#> 540      poisson_log_rng                                   (reals alpha)
#> 541         poisson_lpmf                         (ints n | reals lambda)
#> 542              poisson                                               ~
#> 543          poisson_rng                                  (reals lambda)
#>     ReturnType
#> 532       real
#> 533       real
#> 534       real
#> 535       real
#> 536       real
#> 537       real
#> 538       real
#> 539       real
#> 540          R
#> 541       real
#> 542       real
#> 543          R