[help] tar_stan_mcmc() doesn't accept target for stan_files argument? #67
Replies: 2 comments 1 reply
-
# _targets.R
library(targets)
library(stantargets)
write_stan <- function(dir) {
lines <- "data {
int <lower = 1> n;
vector[n] x;
vector[n] y;
real true_beta;
}
parameters {
real beta;
}
model {
y ~ normal(x * beta, 1);
beta ~ normal(0, 1);
}"
cmdstanr::write_stan_file(lines, dir)
}
generate_data <- function(n = 10) {
true_beta <- stats::rnorm(n = 1, mean = 0, sd = 1)
x <- seq(from = -1, to = 1, length.out = n)
y <- stats::rnorm(n, x * true_beta, 1)
list(n = n, x = x, y = y, true_beta = true_beta)
}
stan_file <- write_stan("persistent_path.stan")
list(
tar_stan_mcmc(
example,
stan_files = stan_file,
generate_data(),
stdout = R.utils::nullfile(),
stderr = R.utils::nullfile()
)
) |
Beta Was this translation helpful? Give feedback.
-
I don't think there would be room in |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Help
Description
I'm aware that this is an unusual use case but I have a {targets} pipeline that generates Stan code files that can change depending on some specification set dynamically in the pipeline. As a result, I have a target in the pipeline that is the path to the Stan file, but
tar_stan_mcmc()
immediately throws an error indicating it doesn't recognize that the object supplied for thestan_files
argument is a target with the path to the Stan file as a character string. I was hoping to not have to define my own functions (or borrow from the targets-stan repo) to run the Stan model, so I am wondering if there is a simple fix to this? Thank you!Here's an example.
The error you should get upon sourcing
_targets.R
isError in eval(ei, envir) : object 'path' not found
.Beta Was this translation helpful? Give feedback.
All reactions