我最近被指向Roxygen解决我的文档困境/懒惰.但是在这个闪亮的Roxygen2中,根据我的理解,它有点像它自己的东西.Hadley的包装工具需要使用Roxygen2,但在任何地方都没有通过走路的方式.
鉴于我在学习过程中从头开始:
是否有一个用户,对于新用户,有利于Roxygen而不是Roxygen2,或者Roxygen2在所有方面都更好?
如果有的话,有哪些资源用于学习(最好是那些不依赖于Roxygen先前知识的资源)?
Roxygen2是否与Roxygen向后兼容(这样投入学习和写作Roxygen的时间会延续下去)?
我记录使用的功能roxygen2有@example.
该示例包含一个包含}符号的字符串.
#' ...
#' @examples
#' \dontrun{
#' ## polyline joining the capital cities of Australian states
#' pl <- "nnseFmpzsZgalNytrXetrG}krKsaif@kivIccvzAvvqfClp~uBlymzA~ocQ}_}iCthxo@srst@"
#'
#' df_polyline <- decodepl(pl)
#' }
#' ...
Run Code Online (Sandbox Code Playgroud)
构建时,示例的文档是
第一个之后的所有东西都}被切断了.
如何逃避,}以便它包含在示例中的字符串中?
我试过反斜杠\{/ \\{没有运气.
哈德利对我的问题的官方回应
解决这个问题非常困难(据我所知,它需要编写一个相当复杂的Rd解析器),而且这种情况很少发生,所以现实情况下,我的待办事项清单永远不会达到很高的水平.
我正在roxygen2用于记录我正在开发的包的数据集.我知道你可以使用roxygen来记录数据集,但Shane的回答最终暗示了一个hack,而我宁愿避免.所以,我的问题是:
我目前有一个数据文档文件(anorexia.sub.roxygen)用于我/ R文件夹中的厌食症数据集

因为据我所知,这是roxygen2寻找它的唯一地方:
#' Family Treatment Weight change data for young female anorexia patients.
#'
#'
#' The MASS package includes the dataset \code{anorexia}, containing pre and
#' post treatment weights for young female anorexia patients. This is a subset
#' of those data, containing only those patients who received Family Treatment.
#'
#'
#' @name anorexia.sub
#' @docType data
#' @format A dataframe with 17 observations on …Run Code Online (Sandbox Code Playgroud) 例如,假设我的包中有一个函数闭包
f = function(x) {
x = x
g = function(y) x <<- y
h = function() x
list(g = g, h = h)
}
l = f(5)
l$g(10)
l$h()
Run Code Online (Sandbox Code Playgroud)
记录此功能的正确方法(在官方CRAN意义上)是什么?特别是,
roxygen2g和文档h我已多次遇到以下问题.
假设您有两个类,classA并classB在以下文件中进行了描述classA.R:
#' the class classA
#'
#' This is a class A blabla
#' \section{Slots}{\describe{\item{\code{A}}{a Character}}}
#' @ name classA
#' @rdname classA
#' @exportClass classA
setClass("classA",representation(A="character"))
Run Code Online (Sandbox Code Playgroud)
和 classB.R
#' the class classB
#'
#' This is a class B blabla
#' \section{Slots}{\describe{\item{\code{B}}{an object of class A}}}
#' @ name classB
#' @rdname classB
#' @exportClass classB
setClass("classB",representation(B="classA"))
Run Code Online (Sandbox Code Playgroud)
我相信这些文件是按字母顺序读取的roxygen2,但事实并非如此.如果我尝试构建包,我可能会收到以下错误:
roxygenize("./myExample")
Error in getClass(Class, where = topenv(parent.frame())) :
"ClassA" is not a …Run Code Online (Sandbox Code Playgroud) 我试图在一个包中使用S3方法,并认为我在这里问一个问题之后理解了如何设置它:使用Roxygen构建R包时的S3方法一致性警告
但现在我得到的结果我没想到.如果我直接在R中运行下面的代码,它会给我预期的结果,但是如果我把它编译成一个包,我就得不到正确的结果(请注意,当它应该只采用唯一的单词时,它会被计算两次vector a).我不确定我的设置是不正确的.
.R文件:
#' Find Common Words Between Groups
#'
#' Find common words between grouping variables (e.g. people).
#'
#' @param word.list A list of names chacter vectors.
#' @param overlap Minimum/exact amount of overlap.
#' @param equal.or A character vector of c(\code{"equal"}, \code{"greater"},
#' \code{"more"}, \code{"less"}).
#' @param \dots In liu of word.list the user may input n number of character
#' vectors.
#' @rdname common
#' @return Returns a dataframe of all words …Run Code Online (Sandbox Code Playgroud) 这比一个问题更令人烦恼,但有没有办法防止在编译R中的文档并且行太长时发生的行"溢出"?
使用以下内容创建的一些文档片段R CMD Rd2pdf [options] files:

我无法在任何地方找到这一点,而Rd2pdf的唯一选择是:
Options:
-h, --help print short help message and exit
-v, --version print version info and exit
--batch no interaction
--no-clean do not remove created temporary files
--no-preview do not preview generated PDF file
--encoding=enc use 'enc' as the default input encoding
--outputEncoding=outenc
use 'outenc' as the default output encoding
--os=NAME use OS subdir 'NAME' (unix or windows)
--OS=NAME the same as '--os'
-o, --output=FILE write output to FILE
--force overwrite output …Run Code Online (Sandbox Code Playgroud) 例如,假设我有以下包调用Test,我想导出类A:
# In /R/Test.R:
#' @docType package
#' @import methods
#' @exportClass A
A <- setRefClass("A", methods = list(foo = identity))
Run Code Online (Sandbox Code Playgroud)
但是,在构建和加载后,使用A的生成器时出现以下错误:
> library(Test)
> A()$foo(1)
Error: could not find function "A"
Run Code Online (Sandbox Code Playgroud)
我检查过我的NAMESPACE文件内容很好:
exportClasses(A)
import(methods)
Run Code Online (Sandbox Code Playgroud)
出了什么问题?为什么不导出我的类生成器?
有没有办法为R闪亮的应用程序生成文档?
没有文档就很难维护一个闪亮的应用程序.
似乎所有的测试/文档生态系统都是为R包结构创建的.也许我们可以为闪亮的应用程序模拟/扩展此行为?
一个例子 :
反应式表达式通常是R闪亮元素,可以包含复杂的数据结构.
filtered_dat <- reactive({
dx[ NAME == input$crr & TOU == input$tou &
PlotYear == input$year. & PlotMonth == input$season]
})
Run Code Online (Sandbox Code Playgroud)
为了给出更多上下文,我在这里使用R shiny构建一个完整的Web应用程序.所有业务逻辑都包含在一个独立的包中.
为了测试Ui,我认为它很复杂(例如可以使用Rselenium),但是从roxygen2注释生成doc 只是解析.拥有这样的工具应该很容易.
我的项目中有一个文件:import_packages.r,包含以下内容:
#' @import reshape2
#' @import ggplot2
#' @import DESeq2
#' @import geneplotter
#' @import survcomp
#' @import gplots
#' @import pheatmap
#' @import RColorBrewer
Run Code Online (Sandbox Code Playgroud)
当我这样做时,devtools:document()这些包不会显示在NAMESPACE文件中,并且实际上并未导入它们.难道我做错了什么?