동일한 패키지에 roxygen2와 doxygen을 사용하십니까? [닫은]
R
사용 하는 패키지가 roxygen2
있습니다. 에 일부 C
코드가 /src
있으며 방금 Doxygen 작업을 시작했습니다. 문서를 결합하거나 roxygen2와 컴파일을 통합하는 방법이 있습니까? C
코드 문서 를 어디에 넣을지에 대한 "모범 사례"가 있습니까?
roxygen2 및 doxygen에 대한 인터넷 검색은 주로 roxygen으로 연결되는 것은 doxygen 결과 와 유사 합니다. Doxyfiles가있는 몇 가지 패키지를 찾았지만 일관된 구성이 없습니다. 예를 들어, lme4는 소스 디렉토리 외부 inst/doc/Doxyfile
에있는 폴더로 출력됩니다 . Matrix의 루트 디렉토리에도 Doxyfile이 있습니다 (그러나 이전 릴리스에서는에있었습니다 .이 문서도 패키지 디렉토리 외부로 내보내집니다.doxygen
lme4
inst
C
패키지 안에 문서 를 포함하지 않을 이유가 있습니까? 아니면 Doxygen이 널리 사용 되었음에도 불구하고 R 패키지 내에서 그렇게 자주 사용되지 않는 이유는 C
무엇입니까?
업데이트 : 관련 roxygen2 기능 요청 참조
개인적으로 모든 스크립트에서 호출하는 "dataManagement"패키지에 다음 코드를 사용합니다. 그것은 roxygen 문서와 예제를 가지고 있습니다. 실제로 document ()를 호출하고 src /의 C 코드에서 doxygen을 실행했습니다. 문서는 inst / doxygen에 넣어서 패키지가 CRAN 준비가되도록합니다.
R 최종 사용자를 위해 설계된 R 문서 는 C 코드를 보지 말아야합니다. 클래식 R 문서에서 C 코드 문서를 통합하지는 않았지만 결과 C 문서를 "비 네트"로 복사하는 것이 좋습니다. .
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()
}
참고 URL : https://stackoverflow.com/questions/20713521/using-roxygen2-and-doxygen-on-the-same-package
'program story' 카테고리의 다른 글
파일을 특정 개정으로 재설정하거나 되돌리려면 어떻게합니까? (0) | 2020.09.04 |
---|---|
Robolectric으로 ViewPager (및 CursorLoader) 테스트 (0) | 2020.09.04 |
즐겨 찾는 콘텐츠가 webview에 올바르게 표시되지 않습니다 (0) | 2020.09.04 |
범위 및 네비게이터 기능을 사용하여 Highcharts에서 열 범위 차트를 만드는 방법은 무엇입니까? (0) | 2020.09.04 |
OAuth 2.0의 클라이언트 비밀 (0) | 2020.09.04 |