我无法让我的包裹通过 R CMD 检查。我使用的是devtools1.9.1版本和Roxygen24.1.1版本。我遇到的问题如下:
Bad \usage lines found in documentation object 'my_fn':
Functions with \usage entries need to have the appropriate \alias
entries, and all their arguments documented.
The \usage entries must correspond to syntactically valid R code.
See chapter 'Writing R documentation files' in the 'Writing R
Extensions' manual.
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,它实际上并没有给我任何指示问题发生的位置。它只是 2 个空格。
我的功能如下:
#' My function
#'
#' Extracts data from the database in order to produce plots and
#' descriptive statistics.
#'
#' @param …Run Code Online (Sandbox Code Playgroud) 我正在使用 devtools 构建 R 包。所有文档都是使用 roxygen2 构建的。对于这些功能来说,这一切都很好,但是我如何为整个包提供一个帮助页面,其中列出了所有可用的功能。
在其他软件包中,每个帮助页面的底部始终有一个指向索引页面的链接:
如何使用 devtools 构建/链接此索引页面?
编辑:如果我通过“?functionName”访问帮助页面,还会将以下输出打印到控制台“使用 functionName 的开发文档”。从 devtools 的 github 存储库中,我找到了 提供此输出的函数 dev-help.R 。在其评论中指出,链接不适用于此开发帮助。
请注意,这仅呈现单个文档文件,因此到包内其他文件的链接将不起作用。
那么如何使用普通文档而不是 dev-help 呢?
问题\xe2\x80\x94 我想导出函数列表作为 R 包的一部分,最好使用 roxygen2。
\n\n更准确地说,我想导出列表中的函数,而不是列表本身。例如,考虑作为闭包生成的函数列表,如下所示:
\n\naddval <- 1:100\nfns <- lapply(addval, function(y) {force(y); function(x) x + y})\nnames(fns) <- paste0("add_", addval)\nRun Code Online (Sandbox Code Playgroud)\n\n那么问题是将函数(fns例如,在 中使用相同的名称)绑定到包环境,然后将它们包含在包的导出函数中。
将函数绑定到包环境可以很容易地完成;一种方法是
\n\nfor (nm in names(fns)) assign(nm, fns[[nm]])\nRun Code Online (Sandbox Code Playgroud)\n\n但是是否可以使用 roxygen2 标签导出函数add_1、add_2等?
更重要的是:我希望 roxygen2 继续NAMESPACE为我管理文件,并且不希望export()直接编写调用。我能看到这样做的唯一方法是编写代码来生成样板文件,例如
#\' @export add_1\nNULL\n\n#\' @export add_2\nNULL\n\n# ...\nRun Code Online (Sandbox Code Playgroud)\n\n或更好
\n\n#\' @export\nadd_1 <- fns[["add_1"]]\n\n#\' @export\nadd_2 <- fns[["add_2"]]\n\n# ...\nRun Code Online (Sandbox Code Playgroud)\n\n(并放弃上面的 for 循环)。
\n\nroxygen2 是否已经拥有相当于此类样板生成的设施,或者我必须自己提供此设施? …
我正在使用 RStudio 为我正在进行的数据分析创建一个包。为了将我的原始数据放入包中,我devtools::use_data_raw()按照本文使用。
我有一个脚本load-raw-data.R,可以加载原始数据并将其组装到数据帧中,然后调用devtools::use_data()该数据帧将其添加到包中。根据文章,load-raw-data.R不在 中/data-raw。/R我已通过框架向该脚本中的函数添加了文档roxygen2,但是当我构建文档时,.Rd并未构建这些函数的文件。我认为这是因为 roxygen2 只查找/R. 有没有办法告诉也可以roxygen2查看?/data-raw或者我一路上误解了什么?
更新:遵循@phil的建议
@phil - 谢谢 - 我尝试了脚本中的其中一个函数 ( load_data_files) load-raw-data.R(请参阅下面添加到 R/data.R 的文档),但在重建包时出现错误:'load_data_files' is not an exported object from 'namespace:clahrcnwlhf'。我已将该@export标签包含在R/data.R. 关于如何解决这个问题有什么想法吗?
`# This script loads the individual component files of the raw dataset
# and stitches them together, saving the result as …Run Code Online (Sandbox Code Playgroud) roxygen2NAMESPACE将根据我的包文档中的指令自动构建一个文件@import。但显然,我如何排序指令并不重要@import,它总是按字母顺序添加导入。
这给我带来了问题:我正在开发一个需要同时导入IRanges和 的包data.table。这两个包都定义了一个名为 的函数shift,因此导入顺序很重要(shift环境中的函数将来自最后加载的包)。
在我的 roxygen2 代码中,我说:
@import data.table
@import IRanges
Run Code Online (Sandbox Code Playgroud)
我把它放在第一位data.table是因为我希望shift函数 fromIRanges覆盖函数 fromdata.table但行的顺序@import似乎并不重要,因为总是将导入行放入文件roxygen2中。然后我收到这条消息:NAMESPACEIRanges
2:加载时用“data.table::shift”替换先前导入的“IRanges::shift”...
我希望情况正好相反;但实际上,即使我碰巧在这里很幸运,我也不想依赖字母顺序来工作。有什么办法可以控制这个吗?
编辑:我相信data.table是在后面,IRanges因为 theI是大写的。
我正在寻找相当于@describeIn它允许我为多个 R 数据对象创建单个文档对象。
我本来希望这样的事情:
\n\n#\' Tree Distances\n#\' \n#\' These datasets contain the distances between sets\n#\' of 10-tip, 11-tip and 12-tip trees.\n#\' \n#\' @name treeDistances\n#\' @keywords datasets\n"treeDistances10"\n"treeDistances11"\n"treeDistances12"\nRun Code Online (Sandbox Code Playgroud)\n\n将生成一个适用于所有三个treeDistances##对象的手册页,类似于使用@describeIn treeDistances Distances between 11-tip trees.
我注意到添加@aliases treeDistance11 treeDistance12文档页面与数据对象相关联,但没有引用“使用”部分 \xe2\x80\x93 中的对象,但我相信有更合适的方法来执行此操作?
所以我正在写一个 R 包。基本文档的一部分是描述文件。在此描述文件中,有一行必须指定用于 CRAN 共享目的的软件包的许可。
我已经尝试以我能想到的任何格式输入许可证,但在执行时仍然失败R CMD check --as-cran,说明
* checking DESCRIPTION meta-information ... WARNING Non-standard license specification: What license is it under? Standardizable: FALSE
到目前为止我已经尝试过:
License: GPL (>=3) License: GPL-3: License: GPL_3 License: GNU Affero General Public License License: GPL
他们都抛出同样的错误。以所有神圣事物的名义,这根偷偷摸摸的绳子应该是什么样子?
描述文件:
Package: lucas
Type: Package
Title: Package to download and create the DB of LUCAS data harmonized
Version: 1.0
Date: 2020-04-28
Authors@R: c(person("Mom", "Iork", email = "samplemail@mail.com", role = c("aut")), person("La", "Ma", email = "samplemail@mail.com", role …Run Code Online (Sandbox Code Playgroud) 我已经制作了一个简单的 R 包(纯 R)来用暴力解决问题,然后我尝试通过编写 Rcpp 脚本来加快代码速度。我编写了一个脚本来将运行时间与“bench”库进行比较。现在,我如何将此脚本添加到我的包中?我尝试添加
#'@importFrom Rcpp cppFunction
Run Code Online (Sandbox Code Playgroud)
在我的 R 脚本之上并将 Rcpp 文件插入 scr 文件夹中,但不起作用。有没有办法将其添加到我的 r 包中,而无需从头开始创建包?抱歉,如果已经被问过,但我对这一切都很陌生,并且完全迷失了。
由于某种原因pkgdown无法解析我的包中的 .Rd 文件之一。roxygen2当我使用@examples标签或替代方案向文档添加示例时,我发现它失败了@example inst/example/add.R。我将函数最小化为两个参数,以便使其更加“可重现”,但仍然出现相同的错误。请在下面找到错误消息、使用该消息生成的 .Rd 文件 devtools::document()以及该函数的 roxygen2 文档。正如您所看到的,我正在使用一个非常简单的示例,运行应该不会出现任何问题...还要说的是,当我运行devtools::check()所有示例时都通过了,所以我不明白为什么pkgdown会失败。
非常感谢你的帮助。
最好的,
Reading 'man/merge.Rd'
Error : Failed to parse Rd in merge.Rd
i unused argument (output_handler = evaluate::new_output_handler(value = pkgdown_print))
Error: callr subprocess failed: Failed to parse Rd in merge.Rd
i unused argument (output_handler = evaluate::new_output_handler(value = pkgdown_print))
Run Code Online (Sandbox Code Playgroud)
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/merge.R
\name{merge}
\alias{merge} …Run Code Online (Sandbox Code Playgroud) 我在同一个家庭中有两个功能.我正在使用roxygen2进行记录,并且可以将它们放在同一个帮助文件中,但不知道如何使文档中的用法字段具有这两个功能.
我试过了:
#' @usage matrix2vectors(cor.mat) vectors2matrix(cor.vect)
Run Code Online (Sandbox Code Playgroud)
这给出了:
matrix2vectors(cor.mat) vectors2matrix(cor.vect)
Run Code Online (Sandbox Code Playgroud)
我试过逗号分隔,它只给出第一个,我尝试了单独的使用标记,它只使用第一个.
如何在roxygen的使用字段中生成两个项目,因此它们将分开(例如?lapply)?
编辑:Per GeeSee的问题,整个.R文件
#' Convert Between Correlation Matrix and Upper Triangle Dataframe
#'
#' Tools to convert between a correlation matrix and a dataframe of upper triangle
#' values and variable components. The dataframe is more intuitive for applying
#' functions while the correlation matrix is more intuitive to visualize.
#'
#' @aliases matrix2vectors, vectors2matrix
#' @usage matrix2vectors(cor.mat)
#' @usage vectors2matrix(cor.vect)
#' @rdname matrix2vectors
#' @param cor.mat A …Run Code Online (Sandbox Code Playgroud)