gpt4 book ai didi

r - devtools::document vs roxygen2::roxygenize

转载 作者:行者123 更新时间:2023-12-04 09:33:41 26 4
gpt4 key购买 nike

关闭。这个问题是opinion-based .它目前不接受答案。












想改进这个问题?更新问题,以便 editing this post 提供事实和引用来回答它.

7年前关闭。




Improve this question




前段时间我在某处读到 devtools::document优于roxygen2::roxygenize对于“复杂的包裹/位置”(这是我记得的),但不幸的是我现在找不到链接,当时我没有加深。

查看相应的帮助页面,我不清楚如何,所以我的问题
是:如果有时最好使用devtools::document而不是roxygen2::roxygenize ,什么时候会这样?适合哪种套餐?

谢谢,卢卡

最佳答案

您正在记忆 roxygen2 README :

Roxygen does a live analysis of your source code: it loads all the code in your package, so it can create documentation using values in an R environment, not just source code. However, simulating package loading is rather tricky to do in general, so there are two ways to do it with roxygen:

  • roxygen2::roxygenise() just sources all files in the R/ directory

  • devtools::document() sources all files in the R/ directory, compiles source code in the src/ directory, loads data in the data/ directory and generally does an accurate job of simulating package loading.

If you have a simple package, you can use roxygenise(), but for anything more complicated, I recommend that you use document().


您可以在 document 中看到这种区别。来电 roxygenise (通过 devtools:::document_roxygen3 )在做了一堆其他事情之后:
> document
function (pkg = ".", clean = FALSE, roclets = c("collate", "namespace",
"rd"), reload = TRUE)
{
if (!is_installed("roxygen2", 3)) {
stop("Please install latest roxygen2", call. = FALSE)
}
pkg <- as.package(pkg)
message("Updating ", pkg$package, " documentation")
man_path <- file.path(pkg$path, "man")
if (!file.exists(man_path))
dir.create(man_path)
if (clean) {
file.remove(dir(man_path, full.names = TRUE))
}
if (!is_loaded(pkg) || (is_loaded(pkg) && reload)) {
try(load_all(pkg, reset = clean))
}
document_roxygen3(pkg, roclets)
clear_topic_index(pkg)
invisible()
}
<environment: namespace:devtools>

> devtools:::document_roxygen3
function (pkg, roclets)
{
with_envvar(r_env_vars(), with_collate("C", roxygen2::roxygenise(pkg$path,
roclets = roclets, load_code = pkg_env)))
}
<environment: namespace:devtools>

关于r - devtools::document vs roxygen2::roxygenize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25104108/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com