rStudio自动完成描述和用法

时间:2014-06-27 08:04:25

标签: r rstudio roxygen2 package-development

我在R的包开发方面相当新,所以这可能是一个愚蠢的问题,但我希望我能在这里得到一些帮助......

我使用Hadley Wickem http://adv-r.had.co.nz/Package-development-cycle.html

的手册在R中开发了一个小包

我切换到dev_mode(),安装()我的包并用库(包名)加载它

一个例子:

#' logging function
#' 
#' This function tries to use logging functionality. If the logging package 
#' isn't installed, it uses a normal print command
#' 
#' @param string the string to print
#' @param level the level of the log output, for example \code{WARN}, 
#' \code{INFO} or \code{ERROR}
#' @examples
#' \dontrun{
#' mylog('for your information')
#' mylog('this is a warning','WARN')
#' }
mylog <- function(string,level='INFO') {
  tryCatch(
    switch(level,
           WARN=logwarn(string),
           ERROR=logerror(string),
           INFO=loginfo(string),
           {logwarn(sprintf('warnlevel "%s" is not defined!',level))
            loginfo(string)}),
    error=function(condition) {
      cat(sprintf('%s: %s\n',level,string))
    })
}

当我现在输入?mylog时,我在rStudio里面的帮助窗口中得到了我的帮助......但是当我尝试使用Tab自动完成时,这个小弹出窗口中没有信息...

所有其他包都有一些信息,如何使用该功能。

希望有人能给我一个暗示......

1 个答案:

答案 0 :(得分:1)

我找到了解决方案......或者至少我希望如此......

在文档中添加@export标记可以帮助并提供自动完成方面的帮助......

#' logging function
#' 
#' This function tries to use logging functionality. If the logging package 
#' isn't installed, it uses a normal print command
#' 
#' @param string the string to print
#' @param level the level of the log output, for example \code{WARN}, 
#' \code{INFO} or \code{ERROR}
#' @export
#' @examples
#' \dontrun{
#' mylog('for your information')
#' mylog('this is a warning','WARN')
#' }
mylog <- function(string,level='INFO') {
  tryCatch(
    switch(level,
           WARN=logwarn(string),
           ERROR=logerror(string),
           INFO=loginfo(string),
           {logwarn(sprintf('warnlevel "%s" is not defined!',level))
            loginfo(string)}),
    error=function(condition) {
      cat(sprintf('%s: %s\n',level,string))
    })
}