[Rd] Understanding the sequence of events when calling the R dpois function

Jason Serviss j@@on@@ervi@@ @ending from ki@@e
Thu May 31 17:25:36 CEST 2018


Hello all,

I am trying to get a better understanding of the underlying code for the stats::dpois function in R and, specifically, what happens under the hood when it is called. I finally managed to track down the C course at: https://github.com/wch/r-source/blob/trunk/src/nmath/dpois.c. It would seem that the dpois C function is taking a double for each of the x and lambda arguments so I am a bit confused why I can provide a vector and matrix to dpois in R, e.g.

dpois(1:5, matrix(runif(2*5, 1, 10), nrow = 5)))

and get a matrix back with the results. Due to this, I was expecting to see a loop, or similar, in the underlying C source but… to no avail. So I have to conclude that either a) there is a step between when I call dpois in R and the C code getting executed that loops over the inputs or b) that there is a construct in the C code (my proficiency here is limited) that is called per input. Any help in enlightening me on what code is responsible for iterating over the multiple inputs (or if someone is feeling energetic, the exact stepwise code that is executed when calling dpois) would be greatly appreciated!!

Kind Regards,
Jason Serviss


	[[alternative HTML version deleted]]



More information about the R-devel mailing list