Hi:
I am attempting to place a couple pre-compiled Stan models into a R package. The rstan_package_skeleton() option had a few bugs, so copied and pasted all files into the package working directory. To be clear, I have my .stan files in the the exec folder.
I am now getting this error when running “Build & Reload”:
Error in file(con, “r”) : cannot open the connection:
I also get the following warnings (to 50):
Warning messages:
1: In readLines(file) : line 3 appears to contain an embedded nul
2: In readLines(file) : line 4 appears to contain an embedded nul
3: In readLines(file) : line 5 appears to contain an embedded nul
4: In readLines(file) : line 6 appears to contain an embedded nul
5: In readLines(file) : line 44 appears to contain an embedded nul
6: In readLines(file) : line 547 appears to contain an embedded nul
7: In readLines(file) : line 548 appears to contain an embedded nul
8: In readLines(file) : line 549 appears to contain an embedded nul
9: In readLines(file) : line 550 appears to contain an embedded nul
10: In readLines(file) : line 551 appears to contain an embedded nul
11: In readLines(file) : line 552 appears to contain an embedded nul
12: In readLines(file) : line 553 appears to contain an embedded nul
13: In readLines(file) : line 554 appears to contain an embedded nul
14: In readLines(file) : line 555 appears to contain an embedded nul
The Build&Reload icon in RStudio doesn’t exactly work in a straighforward fashion with packages such as these. What were the errors you encountered when doing rstantools::rstan_package_skeleton()?
Thank you for the quick response. I just started the package with Rstan_package_skeleton(), and used devtools:document and this worked. I then added my .stan file to the exec folder, and now have the error once again.
error encountered:
Error in file(con, “r”) : cannot open the connection
Here is one of the errors with “rerun wit Debug” (not sure if you want them all):
function (description = “”, open = “”, blocking = TRUE, encoding = getOption(“encoding”),
raw = FALSE, method = getOption(“url.method”, “default”))
{
.Internal(file(description, open, blocking, encoding, method,
raw))
}
Me again. When using the “Build and Reload” I get this unusual error that keeps on running. I have to exit R studio, as the error will not stop.
Warning in readLines(file) :
line 2682 appears to contain an embedded nul
Warning in readLines(file) :
line 2684 apning in readLines(file) :
line 2682 appears to contain an embedded nul
Warning in readLines(file) :
line 2684 ap
I was under the impression that the rstan skeleton tools provide the necessary boilerplate to compile .stan files into SO/DLLs, and that you can’t just compile an object and stick it into your package tree? Has that changed? Otherwise, wouldn’t you have to precompile each stan model for each OS and OS version? Or are you referring to something else?
You can’t call rstantools::rstan_package_skeleton("anRpackage") and then rename the resulting directory to bnets without having to go back and change a bunch of stuff inside that is tied to the package name.
Read the read-and-delete-me file in the root of bnets before deleting it, particularly the part about the NAMESPACE file and making the cleanup files executable
Don’t try to put dll files into the src/ subdirectory; they have to be created as part of the build process.
Got it thank you! One more question :) I am calling the .stan model inside of a function I created, but not sure what the model is called now. It is saved as ridge.stan, but using ridge within the function does not work.
mod_fit <- sampling(ridge, data = stan_dat,
chains = chains, iter = iter, cores = cores,
control = list(adapt_delta = adapt_delta,
max_treedepth = max_treedepth))
OK. I tried that and got the following: “model_ridge” not found.
X <- psych::bfi[1:100, 1:5]
fit <- bridge_net(X, prior_scale = 1, chains = 4)
Error in new_CppObject_xp(fields$.module, fields$.pointer, …) :
no valid constructor available for the argument list
In addition: Warning message:
NA values detected and removed
trying deprecated constructor; please alert package maintainer
Show Traceback
Rerun with Debug
Error in checkForRemoteErrors(val) :
4 nodes produced errors; first error: object ‘model_ridge’ not found
Hmm. Interesting. I tried it and get the same error.
rstan::sampling(stanmodels$ridge,…
Error in new_CppObject_xp(fields$.module, fields$.pointer, …) :
no valid constructor available for the argument list
trying deprecated constructor; please alert package maintainer
Loading required namespace: rstudioapi
Show Traceback
Rerun with Debug
Error in checkForRemoteErrors(val) :
4 nodes produced errors; first error: object ‘model_ridge’ not found
That is Windows stuff. You have to make sure that the right version is installed in the right path to get it to work correctly in parallel for Windows. We can worry about that later. For now, try it with one chain.
Okay, at least you can keep developing it now. Make sure to uninstall any previous versions of the package in different directories and to start R with a clean session that does not bring in any old objects that are Stan-related.
Almost ;-) I added the final two models, and am now getting a similar error as before. I saw that m is used in a loop, so not sure why it is not found. I pushed the two additional models to github
Updating bnets documentation
Loading bnets
Error in is(module, “character”) : object ‘m’ not found
Calls: suppressPackageStartupMessages … load_all -> run_ns_load_actions -> action -> loadModule -> is
Execution halted