【问题标题】:rStudio autocompletion description and usagerStudio 自动补全说明和使用
【发布时间】:2014-06-27 08:04:25
【问题描述】:

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

我使用 Hadley Wickem http://adv-r.had.co.nz/Package-development-cycle.html 的手册在 R 中开发了一个小包

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

举个例子:

#' 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 自动完成功能时,这个小弹出窗口中没有任何信息...

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

希望有人能给我提示...

【问题讨论】:

  • 谢谢你的问题,这也是我要找的。​​span>
  • 其实好像找到了解决方案...我必须导出带有@export标签的函数...现在帮助出现...

标签: r rstudio roxygen2 package-development


【解决方案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))
    })
}    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-28
    • 2014-05-18
    • 2013-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-03
    • 1970-01-01
    相关资源
    最近更新 更多