avehtari/BDA_course_Aalto

dmvnorm expects the first argument to have only one class

itulkki opened this issue · 2 comments

The dmvnorm function checks whether the first argument is a matrix or not. This check is done by checking if class(x) is ‘matrix’. However, class(x) may return a list of class strings. In this case, R decides to do the comparison separately for each element of the list. This will cause an error if the result of the comparison varies between elements.

This bug can be fixed by replacing if (class(x) == ‘matrix’) with if (‘matrix’ %in% class(x)) in the dmvnorm function.

I have attached a small R script that demonstrates this problem. It is a .txt file since GitHub does not support .r files.
bug_demo.txt

I think you might be using an outdated version of the package, since the code currently uses any() to detect the class match:

if (any(class(x) == "matrix")) {

Closing since the provided code does not error with the current version of the package, but thanks for the bug report and feel free to reopen if you're still having issues!