如何管理R扩展/包文档(或至少没有痛苦)

时间:2021-11-29 11:19:12

Now and then I embrace project specific code in R packages. I use the documentation files as suggested by Writing R Extensions to document the application of the code.

偶尔我会在R包中包含项目特定的代码。我使用Writing R Extensions建议的文档文件来记录代码的应用。

So once you set up your project and did all the editing to the .Rd files, how do you manage a painless and clean versioning without rewriting or intense copy-pasting of all the documentation files in case of code or, even worse, code structure changes?

因此,一旦您设置了项目并对.Rd文件进行了所有编辑,如何在不对代码进行重写或对所有文档文件进行大量复制粘贴的情况下管理无痛且干净的版本控制,或者更糟糕的是代码结构变化?

To be more verbose, my current workflow is that I issue package.skeleton(), do the editing on the .Rd-files followed by R CMD check and R CMD build. When I do changes to my code I need to redo the above maybe appending '.2.0.1' or whatever in order to preserve the precursor version. Before running the R CMD check command I need to repopulate all the .Rd-files with great care in order to get a clean check and succsessful compilation of Tex-files. This is really silly and sometimes a real pain, e.g. if you want to address all the warnings or latex has a bad day.

为了更加详细,我目前的工作流程是发出package.skeleton(),对.Rd文件进行编辑,然后进行R CMD检查和R CMD构建。当我对我的代码进行更改时,我需要重做上面的内容,可能附加'.2.0.1'或其他任何内容以保留前驱版本。在运行R CMD检查命令之前,我需要非常小心地重新填充所有.Rd文件,以便对Tex文件进行干净的检查和完美的编译。这真的很愚蠢,有时真的很痛苦,例如如果你想解决所有的警告或乳胶有一个糟糕的一天。

What tricks do you use? Please share your workflow.

你用了什么技巧?请分享您的工作流程。

1 个解决方案

#1


1  

The solution you're looking for is roxygen2.

你正在寻找的解决方案是roxygen2。

RStudio provides a handy guide, but briefly you document your function in-line with the function definition:

RStudio提供了一个方便的指南,但是您可以简要地在函数定义中记录您的函数:

#' Function doing something
#' Extended description goes here
#' @param x Input foo blah
#' @return A numeric vector length one containing foo
myFunc <- function(x) NULL

If you're using RStudio (and maybe ESS also?) the Build Package command automagically creates the .Rd files for you. If not, you can read the roxygen2 documentation for the commands to generate the docs.

如果您正在使用RStudio(也可能是ESS?),Build Package命令会自动为您创建.Rd文件。如果没有,您可以阅读roxygen2文档以获取生成文档​​的命令。

#1


1  

The solution you're looking for is roxygen2.

你正在寻找的解决方案是roxygen2。

RStudio provides a handy guide, but briefly you document your function in-line with the function definition:

RStudio提供了一个方便的指南,但是您可以简要地在函数定义中记录您的函数:

#' Function doing something
#' Extended description goes here
#' @param x Input foo blah
#' @return A numeric vector length one containing foo
myFunc <- function(x) NULL

If you're using RStudio (and maybe ESS also?) the Build Package command automagically creates the .Rd files for you. If not, you can read the roxygen2 documentation for the commands to generate the docs.

如果您正在使用RStudio(也可能是ESS?),Build Package命令会自动为您创建.Rd文件。如果没有,您可以阅读roxygen2文档以获取生成文档​​的命令。