我对R的包开发很新,所以这可能是一个愚蠢的问题,但我希望我能在这里得到一些帮助......
我使用Hadley Wickem的手册在R中开发了一个小包装http://adv-r.had.co.nz/Package-development-cycle.html
我切换到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自动完成时,这个小弹出窗口中没有信息......
所有其他包都有一些信息,如何使用该功能 .
希望有人能给我一个暗示......
1 回答
我找到了解决方案......或者至少我希望如此......
在文档中添加
@export
标记有助于并在自动完成中提供帮助...