C 在同一包装上使用roxygen2和doxygen?

C 在同一包装上使用roxygen2和doxygen?,c,r,documentation,doxygen,roxygen2,C,R,Documentation,Doxygen,Roxygen2,我有一个R软件包,它使用roxygen2。它在/src中有一些C代码,我刚刚开始使用Doxygen。是否有任何方法可以将文档合并,或将编译与roxygen2集成?关于将C代码文档放在哪里,有什么“最佳实践”吗 谷歌搜索roxygen2和doxygen主要导致roxygen与doxygen类似的结果。我发现了一些包含DoxyFile的包,但没有一致的组织。例如,lme4在lme4源目录之外有一个名为doxygen的文件夹的输出。矩阵的根目录中还有一个Doxyfile(但在以前的版本中是在inst中

我有一个
R
软件包,它使用
roxygen2
。它在
/src
中有一些
C
代码,我刚刚开始使用Doxygen。是否有任何方法可以将文档合并,或将编译与roxygen2集成?关于将
C
代码文档放在哪里,有什么“最佳实践”吗

谷歌搜索roxygen2和doxygen主要导致roxygen与doxygen类似的结果。我发现了一些包含DoxyFile的包,但没有一致的组织。例如,lme4在
lme4
源目录之外有一个名为
doxygen
的文件夹的输出。矩阵的根目录中还有一个Doxyfile(但在以前的版本中是在
inst
中)。此文档也导出到包目录之外

是否有任何理由不将
C
文档包含在软件包中,或者为什么在广泛使用
C
的情况下,Doxygen在R软件包中很少使用


更新:参见相关我个人在我所有脚本中调用的“数据管理”包中使用了以下代码。它有roxygen文档和示例。实际上,您只需调用 文件( 让doxygen在C代码上运行 src/ 1.文件已经放进去了 仪器/强氧 这样你的包裹就准备好了

R文档是为R最终用户设计的,不应该查看C代码。我没有将C代码文档集成到经典的R文档中,但将生成的C文档作为“小插曲”复制可能是一个好的做法

library(“testthat”)
库(“devtools”)
#“@title替换内存中文件上给定标记的值
#“@description扫描行并更改命名标记的值(如果一行有此标记),
#'如果没有行具有此标记,则在末尾添加一行,如果有多行,则返回警告
#'匹配标签
#“@param filestring一个向量,每个字符串包含一行文件
#“@param标记要搜索的标记
#“@param newVal标记的新值
#“@返回具有新值的字符串向量
#“@示例

“FakFrFrestReST”不回答你的问题,但是如果你使用Rcpp,你可以使用RoxGy2来记录你的导出C++函数。Doxygen在R包中不使用,因为人们不记录他们的C代码。C代码几乎从来没有API和R包的一部分提供,所以人们只是不记录它。如果你想把你的C文档。在包中,只需从Makefile生成HTML并将其放入inst/。我不知道roxygen,但它可能有一些xml输出,就像doxygen一样,您可以将它与一些xslt结合起来,然后从中创建一个完整的文档。您是想在doxyten输出中包含roxygen2输入还是以其他方式?谢谢!我想我没有意识到简单的解决方案是重新定义
devtools::document
来添加对
doxygen path/to/Doxyfile
的系统调用。我已经将此添加到了我的包中。我还添加了一个@hadleySo-据我所知,对此功能的pull请求不是。因为我仍然希望有一种方便的方法来创建doxygen文档,所以我基于上面的代码创建了一个小程序。
    library("testthat")
    library("devtools")

    #' @title Replace a value for a given tag on file in memory
    #' @description Scan the lines and change the value for the named tag if one line has this tag, 
    #'    add a line at the end if no line has this tag and return a warning if several lines
    #'    matching the tag
    #' @param fileStrings A vector with each string containing a line of the file
    #' @param tag The tag to be searched for 
    #' @param newVal The new value for the tag
    #' @return The vector of strings with the new value
    #' @examples
    #' fakeFileStrings <- c("Hello = world","SURE\t= indeed","Hello = you")
    #' 
    #' expect_warning(ReplaceTag(fakeFileStrings,"Hello","me"))
    #' 
    #' newFake <- ReplaceTag(fakeFileStrings,"SURE","me")
    #' expect_equal(length(newFake), length(fakeFileStrings))
    #' expect_equal(length(grep("SURE",newFake)), 1)
    #' expect_equal(length(grep("me",newFake)), 1)
    #' 
    #' newFake <- ReplaceTag(fakeFileStrings,"Bouh","frightened?")
    #' expect_equal(length(newFake), length(fakeFileStrings)+1)
    #' expect_equal(length(grep("Bouh",newFake)), 1)
    #' expect_equal(length(grep("frightened?",newFake)), 1)
    ReplaceTag <- function(fileStrings,tag,newVal){
        iLine <- grep(paste0("^",tag,"\\>"),fileStrings)
        nLines <- length(iLine)
        if(nLines == 0){
            line <- paste0(tag,"\t= ",newVal)
            iLine <- length(fileStrings)+1
        }else if (nLines > 0){
            line <- gsub("=.*",paste0("= ",newVal),fileStrings[iLine])
            if(nLines >1){
                warning(paste0("File has",nLines,"for key",tag,"check it up manually"))
            }
        }
        fileStrings[iLine] <- line
        return(fileStrings)
    }
    #' Prepares the R package structure for use with doxygen
    #' @description Makes a configuration file in inst/doxygen
    #'     and set a few options: 
    #'     \itemize{
    #'        \item{EXTRACT_ALL = YES}
    #'        \item{INPUT = src/}
    #'        \item{OUTPUT_DIRECTORY = inst/doxygen/}
    #'     }
    #' @param rootFolder The root of the R package
    #' @return NULL
    #' @examples 
    #' \dontrun{
    #' DoxInit()
    #' }
    #' @export
    DoxInit <- function(rootFolder="."){
        doxyFileName <- "Doxyfile"
        initFolder <- getwd()
        if(rootFolder != "."){
            setwd(rootFolder)
        }
        rootFileYes <- length(grep("DESCRIPTION",dir()))>0
        # prepare the doxygen folder
        doxDir <- "inst/doxygen"
        if(!file.exists(doxDir)){
            dir.create(doxDir,recursive=TRUE)
        }
        setwd(doxDir)

        # prepare the doxygen configuration file
        system(paste0("doxygen -g ",doxyFileName))
        doxyfile <- readLines("Doxyfile")
        doxyfile <- ReplaceTag(doxyfile,"EXTRACT_ALL","YES")
        doxyfile <- ReplaceTag(doxyfile,"INPUT","src/")
        doxyfile <- ReplaceTag(doxyfile,"OUTPUT_DIRECTORY","inst/doxygen/")
        cat(doxyfile,file=doxyFileName,sep="\n")
        setwd(initFolder)
        return(NULL)
    }

    #' devtools document function when using doxygen
    #' @description Overwrites devtools::document() to include the treatment of 
    #'    doxygen documentation in src/
    #' @param doxygen A boolean: should doxygen be ran on documents in src?
    #'     the default is TRUE if a src folder exist and FALSE if not
    #' @return The value returned by devtools::document()
    #' @example
    #' \dontrun{
    #' document()
    #' }
    #' @export
    document <- function(doxygen=file.exists("src")){
        if(doxygen){
            doxyFileName<-"inst/doxygen/Doxyfile"
            if(!file.exists(doxyFileName)){
                DoxInit()
            }
            system(paste("doxygen",doxyFileName))
        }
        devtools::document()
    }