stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.02k stars 264 forks source link

Fix js lookup syntax error #1100

Closed andrjohns closed 9 months ago

andrjohns commented 9 months ago

Summary:

The onLoad action for rstan currently uses the $validate() member function to check the stanc.js in StanHeaders, and if the check fails then loads the stanc.js from rstan. However, $validate() assumes that the input is a string of JS code, not a file path. This means that the check is always FALSE, and the rstan stanc.js is always loaded.

This PR simplifies that to just checking whether the file exists.

Copyright and Licensing

Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company): Andrew Johnson

By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses:

bgoodri commented 9 months ago

The mustWork = TRUE argument to system.file already requires the file to exist, but if it exists in the corrupted state, it will cause things to break. I will put this in .onLoad in the the 2.32 branch to get around it:

  stanc_js <- system.file("stanc.js", package = "StanHeaders", mustWork = TRUE)
  test <- try(stanc_ctx$source(stanc_js), silent = TRUE)
  if (inherits(test, "try-error")) {
    stanc_js <- system.file("exec", "stanc.js", package = "rstan", mustWork = TRUE)
    stanc_ctx$source(stanc_js)
  }