我运行devtools::test
,它可以正常工作:
$ RScript -e "devtools::test()"
...
OK: 24
但是devtools::check
在测试中失败:
$ RScript -e "devtools::check()"
...
> test_check("package")
Error in cpp_object_initializer(.self, .refClassDef, ...) :
could not find function "cpp_object_initializer"
Stan model 'bayes_logit' does not contain samples.
── 1. Error: Mixture of Dirichlet Processes stick-breaking works and returns (@t
'data' must be of a vector type, was 'NULL'
1: mdp_logit_mvn_stickbreaking(n_samp = n_samp, mix_mean = NULL, mix_cov = NULL, posterior_sample = stan_sample,
prior_sample_size = 1, dataset = german, tol = 1e-08) at testthat/test_stick_breaking.R:35
2: MASS::mvrnorm(n = n_samp, mu = mix_mean, Sigma = mix_cov)
3: eigen(Sigma, symmetric = TRUE)
4: unname(as.matrix(x))
5: as.matrix(x)
6: as.matrix.default(x)
7: array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), NULL) else NULL)
我该如何解决?
答案 0 :(得分:0)
这是由于加载和附着之间的差异。我从this GitHub issue那里获得了解决方案。
在NAMESPACE
中添加此内容以告诉R在哪里找到cpp_object_initialiser
:
Depends:
Rcpp
这可行,但是给您一个注释。为避免出现此注释,请在使用Rstan调用的函数周围添加Roxygen导出:
#' @importFrom Rcpp cpp_object_initializer
function_name <- function(...) {...}