rstan() 不应该在#'@example 中 运行 吗?
rstan() should not run in #'@example?
在包开发中,每个示例需要<5s。但是,stan_model()
和 rstan::sampling()
这对花费了超过 5s 的时间如下:
Examples with CPU or elapsed time > 5s
user system elapsed
fit 1.25 0.11 32.47
所以我在 roxygen 评论 #'@examples
中为每个 rstan::sampling()
添加了 \donttest{}
例子#'@examples
,我们不应该运行 sampling()
或者有什么治疗方法吗?
我曾尝试根据您教我的代码 rstan_package_skeleton(path = 'BayesianAAA')
创建我的包(谢谢!!)但是,我对它的很多事情都不了解。
之前rstan_package_skeleton(path = 'BayesianAAA')
在我的电脑上启动报错(现在不报错了)。
所以,我制作的包裹没有 rstan_package_skeleton()
,比如说 BayesianAAA
,而在我原来的制作中,我放了 Model_A.stan
、Model_B.stan
、Model_C.stan
、.. .. 在 inst/extdata
中,我按如下方式引用我的 stan 文件;
scr <- system.file("extdata", "Model_A.stan", package="BayesianAAA")
scr <- rstan::stan_model(scr)
我对代码有很多疑问 rstan_package_skeleton(path = 'BayesianAAA')
。
1) 第一个问题 是如何包含我现有的 stan 文件和 如何引用 我的 .stan
文件rstan::stan_model()
?
根据下一页,它说
如果我们有现有的 .stan 文件要包含在包中,我们可以使用 rstan_package_skeleton 的可选 stan_files
参数来包含它们。
所以,我想我应该执行,我不确定,但需要以下类似的方式;
`rstan_package_skeleton(path = 'BayesianAAA', stan_files = "Model_A.stan" )`.
但我不知道如何为几个 stan 文件编写代码,例如 Model_A.stan
、Model_B.stan
、Model_C.stan
在我现有的没有 rstan_package_skeleton()
的包中.我不明白,但是下面的代码是正确的吗?由于我没有在变量stan_files
中描述的文件反映在rstan_package_skeleton()
创建的新项目中。
`rstan_package_skeleton(path = 'BayesianAAA', stan_files = c("Model_A.stan",`Model_B.stan`,`Model_C.stan` )`.
这里,又出现了一个问题,即
2)第二个问题:我在哪里执行代码rstan_package_skeleton(path = 'BayesianAAA', stan_files = "Model_A.stan" )
?我在我现有的包项目中从 R studio 控制台执行它。这是正确的吗 ?然后,新项目出现,它包含旧的现有项目。我应该怎么办 ?
https://cran.r-project.org/web/packages/rstantools/vignettes/minimal-rstan-package.html
3) 我不太了解包 "rstanarm" ,但我尝试为我的包模仿它,但是我不能在其中罚款任何 .stan
文件,我错了吗?
对不起我的英语不好,而且对这些东西缺乏研究。
如果你能告诉我,我将不胜感激。
你通常不应该编写一个在运行时调用 stan_model
的包,除非像 brms 或 tmbstan 你是在运行时生成一个 Stan 程序,而不是静态地编写它。 CRAN 上有几十个包,它们基本上按照为 rstanarm 开发的构建过程提供编译的 Stan 程序,这是由 rstantools::rstan_package.skeleton
函数、step-by-step guide, and the developer guidelines 促进的这直接解决了你的问题
CRAN policy permits long installation times but imposes restrictions on the time consumed by examples and unit tests that are much shorter than the time that it takes to compile even a simple Stan program. Thus, it is only possible to adequately test your package if it has pre-compiled Stan programs.
即便如此,也很难在五秒内从后验分布中(充分地)采样,因此您通常不得不使用小数据集、一个链、少量迭代等。
最好将您的 Stan 程序的名称(应以 .stan 扩展名结尾,否则不要使用句点,名称中只能包含 ASCII 字母、数字和下划线)传递给 rstantools::rstan_package_skeleton()
。如果从 RStudio 这样做,我会在不在现有项目中时调用它。那么
During installation, all Stan programs will be compiled and saved in the list stanmodels
that can then be used by R function in the package. The rule is that the Stan program compiled from the model code in src/stan_files/foo.stan
is stored as list element stanmodels$foo
.
有几十个 R 包在它们的 src/stan_files
目录中有 Stan 程序(尽管 Stan 程序的位置将移动到 inst/stan
用于下一个 rstantools 发布),大部分只是遵循小插曲,除了编写更多 R 函数外,无需执行任何其他步骤。
在包开发中,每个示例需要<5s。但是,stan_model()
和 rstan::sampling()
这对花费了超过 5s 的时间如下:
Examples with CPU or elapsed time > 5s
user system elapsed
fit 1.25 0.11 32.47
所以我在 roxygen 评论 #'@examples
rstan::sampling()
添加了 \donttest{}
例子#'@examples
,我们不应该运行 sampling()
或者有什么治疗方法吗?
我曾尝试根据您教我的代码 rstan_package_skeleton(path = 'BayesianAAA')
创建我的包(谢谢!!)但是,我对它的很多事情都不了解。
之前rstan_package_skeleton(path = 'BayesianAAA')
在我的电脑上启动报错(现在不报错了)。
所以,我制作的包裹没有 rstan_package_skeleton()
,比如说 BayesianAAA
,而在我原来的制作中,我放了 Model_A.stan
、Model_B.stan
、Model_C.stan
、.. .. 在 inst/extdata
中,我按如下方式引用我的 stan 文件;
scr <- system.file("extdata", "Model_A.stan", package="BayesianAAA")
scr <- rstan::stan_model(scr)
我对代码有很多疑问 rstan_package_skeleton(path = 'BayesianAAA')
。
1) 第一个问题 是如何包含我现有的 stan 文件和 如何引用 我的 .stan
文件rstan::stan_model()
?
根据下一页,它说
如果我们有现有的 .stan 文件要包含在包中,我们可以使用 rstan_package_skeleton 的可选 stan_files
参数来包含它们。
所以,我想我应该执行,我不确定,但需要以下类似的方式;
`rstan_package_skeleton(path = 'BayesianAAA', stan_files = "Model_A.stan" )`.
但我不知道如何为几个 stan 文件编写代码,例如 Model_A.stan
、Model_B.stan
、Model_C.stan
在我现有的没有 rstan_package_skeleton()
的包中.我不明白,但是下面的代码是正确的吗?由于我没有在变量stan_files
中描述的文件反映在rstan_package_skeleton()
创建的新项目中。
`rstan_package_skeleton(path = 'BayesianAAA', stan_files = c("Model_A.stan",`Model_B.stan`,`Model_C.stan` )`.
这里,又出现了一个问题,即
2)第二个问题:我在哪里执行代码rstan_package_skeleton(path = 'BayesianAAA', stan_files = "Model_A.stan" )
?我在我现有的包项目中从 R studio 控制台执行它。这是正确的吗 ?然后,新项目出现,它包含旧的现有项目。我应该怎么办 ?
https://cran.r-project.org/web/packages/rstantools/vignettes/minimal-rstan-package.html
3) 我不太了解包 "rstanarm" ,但我尝试为我的包模仿它,但是我不能在其中罚款任何 .stan
文件,我错了吗?
对不起我的英语不好,而且对这些东西缺乏研究。 如果你能告诉我,我将不胜感激。
你通常不应该编写一个在运行时调用 stan_model
的包,除非像 brms 或 tmbstan 你是在运行时生成一个 Stan 程序,而不是静态地编写它。 CRAN 上有几十个包,它们基本上按照为 rstanarm 开发的构建过程提供编译的 Stan 程序,这是由 rstantools::rstan_package.skeleton
函数、step-by-step guide, and the developer guidelines 促进的这直接解决了你的问题
CRAN policy permits long installation times but imposes restrictions on the time consumed by examples and unit tests that are much shorter than the time that it takes to compile even a simple Stan program. Thus, it is only possible to adequately test your package if it has pre-compiled Stan programs.
即便如此,也很难在五秒内从后验分布中(充分地)采样,因此您通常不得不使用小数据集、一个链、少量迭代等。
最好将您的 Stan 程序的名称(应以 .stan 扩展名结尾,否则不要使用句点,名称中只能包含 ASCII 字母、数字和下划线)传递给 rstantools::rstan_package_skeleton()
。如果从 RStudio 这样做,我会在不在现有项目中时调用它。那么
During installation, all Stan programs will be compiled and saved in the list
stanmodels
that can then be used by R function in the package. The rule is that the Stan program compiled from the model code insrc/stan_files/foo.stan
is stored as list elementstanmodels$foo
.
有几十个 R 包在它们的 src/stan_files
目录中有 Stan 程序(尽管 Stan 程序的位置将移动到 inst/stan
用于下一个 rstantools 发布),大部分只是遵循小插曲,除了编写更多 R 函数外,无需执行任何其他步骤。