wjakethompson / measr

R package for the Bayesian estimation of diagnostic classification models using Stan
https://measr.info
GNU General Public License v3.0
8 stars 3 forks source link

testthat self-test fails with package dependency issues #22

Closed ralmond closed 9 months ago

ralmond commented 1 year ago

Running the "Test" from the build window in RStudio fails with the following error messages:

==> devtools::test()

ℹ Testing measr
Error in load_imports(path) : The packages "dplyr" (>=
1.1.1) and "tidyr" (>= 1.3.0)
are required.
Calls: <Anonymous> ... load_imports -> deps_check_installed -> check_installed
Execution halted

Exited with status 1.

I have the tidyverse packages installed.

wjakethompson commented 1 year ago

What does devtools::session_info(c("dplyr", "tidyr")) give you?

ralmond commented 1 year ago

Ah! I had older versions of dplyr and tidyr set (from Debian sources rather than direct from CRAN).

Next I ran into a problem as the test suite uses cmdstanr which is not on CRAN. You might need to add install.packages("cmdstanr", repos=c(stan="https://mc-stan.org/r-packages/",CRAN="https://cloud.r-project.org/")) to your readme file.

There apparently also is some setup needed for cmdstanr as I'm getting 5 failures in the test suite:

==> devtools::test()

ℹ Testing measr
✔ | F W S  OK | Context
✔ |       188 | data-checks [1.7s]
✔ |        41 | data [0.1s]      
✖ | 1       0 | ecpe [0.4s]      
─────────────────────────────────
Error (test-ecpe.R:3:1): (code run outside of `test_that()`)
Error: CmdStan path has not been set yet. See ?set_cmdstan_path.
Backtrace:
 1. utils::capture.output(...)
      at test-ecpe.R:3:0
 5. measr::measr_dcm(...)
 6. measr:::create_stan_function(...)
      at measr/R/fit-dcm.R:153:2
 7. cmdstanr::cmdstan_model(...)
      at measr/R/stan-utils.R:93:4
 8. cmdstanr::cmdstan_version()
 9. cmdstanr:::stop_no_path()
─────────────────────────────────
✔ |        17 | extract [0.5s]   
✔ |        34 | m2-methods [6.6s]
✖ | 1       0 | mcmc [0.2s]      
─────────────────────────────────
Error (test-mcmc.R:3:1): (code run outside of `test_that()`)
Error: CmdStan path has not been set yet. See ?set_cmdstan_path.
Backtrace:
 1. utils::capture.output(...)
      at test-mcmc.R:3:0
 5. measr::measr_dcm(...)
 6. measr:::create_stan_function(...)
      at measr/R/fit-dcm.R:153:2
 7. cmdstanr::cmdstan_model(...)
      at measr/R/stan-utils.R:93:4
 8. cmdstanr::cmdstan_version()
 9. cmdstanr:::stop_no_path()
─────────────────────────────────
✔ |        20 | methods [41.1s]  
✔ |        42 | param-estimates [0.2s]
✔ |        67 | priors [0.5s]    
✔ |        19 | reliability [6.8s]
✖ | 3      15 | stan-scripts [2.1s]
─────────────────────────────────
Failure (test-stan-scripts.R:27:3): stan generated quantities script works
`prob_code` (`actual`) not equal to stanmodels$gqs_probs@model_code (`expected`).

lines(actual)[19:24] vs lines(expected)[19:25]
  "}"
  "generated quantities {"
  "  matrix[R,C] prob_resp_class;   // post prob of respondent R in class C"
  "  matrix[R,A] prob_resp_attr;    // post prob of respondent R master A"
+ "  "
  "  for (r in 1:R) {"
  "    row_vector[C] prob_joint;"
  "    for (c in 1:C) {"

lines(actual)[32:37] vs lines(expected)[33:39]
  "      prob_joint[c] = log_Vc[c] + sum(log_items);"
  "    }"
  "    prob_resp_class[r] = exp(prob_joint) / exp(log_sum_exp(prob_joint));"
  "  }"
+ ""
  "  for (r in 1:R) {"
  "    for (a in 1:A) {"
  "      row_vector[C] prob_attr_class;"

lines(actual)[40:44] vs lines(expected)[42:46]
  "      }"
  "      prob_resp_attr[r,a] = sum(prob_attr_class);"
  "    }"
- "  }"
+ "  } "
  "}"

Failure (test-stan-scripts.R:35:3): stan generated quantities script works
`ppmc_code` (`actual`) not equal to stanmodels$gqs_ppmc@model_code (`expected`).

lines(actual)[21:26] vs lines(expected)[21:27]
  "  matrix[R,C] prob_resp_class;   // post prob of respondent R in class C"
  "  matrix[R,A] prob_resp_attr;    // post prob of respondent R master A"
  "  int y_rep[N];"
  "  int r_class[R];"
+ ""
  "  for (r in 1:R) {"
  "    row_vector[C] prob_joint;"
  "    for (c in 1:C) {"

lines(actual)[34:39] vs lines(expected)[35:41]
  "      prob_joint[c] = log_Vc[c] + sum(log_items);"
  "    }"
  "    prob_resp_class[r] = exp(prob_joint) / exp(log_sum_exp(prob_joint));"
  "  }"
+ ""
  "  for (r in 1:R) {"
  "    for (a in 1:A) {"
  "      row_vector[C] prob_attr_class;"

lines(actual)[42:48] vs lines(expected)[44:51]
  "      }"
  "      prob_resp_attr[r,a] = sum(prob_attr_class);"
  "    }"
- "  }"
+ "  } "
+ ""
  "  for (r in 1:R) {"
  "    vector[C] r_probs = exp(log_Vc) / exp(log_sum_exp(log_Vc));"
  "    r_class[r] = categorical_rng(r_probs);"

Failure (test-stan-scripts.R:45:3): stan log_lik script works
`loglik_code` (`actual`) not equal to stanmodels$gqs_loglik@model_code (`expected`).

lines(actual)[18:23] vs lines(expected)[18:24]
  "  matrix[I,C] pi;"
  "}"
  "generated quantities {"
  "  vector[R] log_lik;"
+ ""
  "  for (r in 1:R) {"
  "    row_vector[C] prob_joint;"
  "    for (c in 1:C) {"
─────────────────────────────────
✔ |        14 | stan-utils       
✔ |         2 | utils-display    
✔ |        11 | utils-priors     
✔ |         6 | utils [0.1s]     

══ Results ══════════════════════
Duration: 60.6 s

[ FAIL 5 | WARN 0 | SKIP 0 | PASS 476 ]
wjakethompson commented 1 year ago

Ah, yes. I don't have installation instructions for cmdstanr because it is not strictly required. By default, measr will use the rstan package as a backend to estimate models, because the cmdstanr package is not yet on CRAN. Thus, cmdstanr is optional, but I've included tests to ensure that cmdstanr works, if the user has it installed and chooses to use it. I've opened another issue (#23) to track adding more installation instructions to the package vignettes. For now, this code should get everything working for you:

install.packages("remotes")
remotes::install_github("stan-dev/cmdstanr")
cmdstanr::install_cmdstan()
ralmond commented 1 year ago

Probably the way to do this is to add skip logic to the test. So it checks to see if cmdstanr is installed, and skips the test if not.

—Russell

On Jun 20, 2023, at 10:01, Jake Thompson @.***> wrote:

Ah, yes. I don't have installation instructions for cmdstanr because it is not strictly required. By default, measr will use the rstan package as a backend to estimate models, because the cmdstanr package is not yet on CRAN. Thus, cmdstanr is optional, but I've included tests to ensure that cmdstanr works, if the user has it installed and chooses to use it. I've opened another issue (#23 https://github.com/wjakethompson/measr/issues/23) to track adding more installation instructions to the package vignettes. For now, this code should get everything working for you:

install.packages("remotes") remotes::install_github("stan-dev/cmdstanr") cmdstanr::install_cmdstan() — Reply to this email directly, view it on GitHub https://github.com/wjakethompson/measr/issues/22#issuecomment-1598857344, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANPQASX4SSDLZCTQYP4DMTXMGUM7ANCNFSM6AAAAAAZFBLY7U. You are receiving this because you authored the thread.