【问题标题】:Funtion exporting with Roxygen2 is exporting all the functions in my code instead of the one I want使用 Roxygen2 导出函数是导出我的代码中的所有函数,而不是我想要的函数
【发布时间】:2019-06-16 18:15:28
【问题描述】:

我是第一次构建自己的包,最终构建没有问题。问题是我只使用 Roxygen2 (6.0.1) 导出一个函数,因为它是唯一一个要使用的函数,但是当我构建和加载我的包时,其中存在的所有函数都被导出。 (当我查看 package:: 时)

我一直在寻找类似的事件,但没有找到任何

这是函数之前的 Roxygen cmets:

#' Do a plot
#'
#' @param region a GRange object with chr, start, end
#' @param genome a character vector "hg19","hg38" or "mm10"
#' @param BAM a path to the BAM related csv input file
#' @param BED a path to the BED related csv input file
#' @param avgTrack a logical indicating if the average track should be present or not
#' @param geneTrack a logical indicating if the gene track should be present or not
#' @param max a vector of number containing the maximum of each BAM track
#'
#' @export
myfunction <- function(){}

这是由 Roxygen2 生成的 NAMESPACE:

# Generated by roxygen2: do not edit by hand

export(myfunction)
importFrom(GenomicRanges,findOverlaps)
importFrom(IRanges,elementNROWS)
importFrom(IRanges,splitAsList)
importFrom(S4Vectors,List)
importFrom(S4Vectors,queryHits)
importFrom(S4Vectors,subjectHits)
importFrom(S4Vectors,subjectLength)
importFrom(biomaRt,getBM)
importFrom(grDevices,hcl)
importFrom(graphics,axis)
importFrom(graphics,legend)
importFrom(graphics,lines)
importFrom(graphics,par)
importFrom(graphics,plot)
importFrom(graphics,plot.new)
importFrom(graphics,rect)
importFrom(graphics,segments)
importFrom(graphics,text)
importFrom(rbamtools,bamCount)
importFrom(rbamtools,bamReader)
importFrom(rbamtools,getRefCoords)
importFrom(utils,read.table)

当我执行 mypackage:: 时,我应该只显示一个函数 (mypackage::myfunction),因为我得到了代码中的所有函数。

【问题讨论】:

  • 你的所有函数都有#' @export吗?
  • 不,只是在第一个,但第一个正在使用所有其他功能。
  • “我得到了我的代码中的所有函数”是什么意思?您的所有函数都在 NAMESPACE 中,还是只是您导入的那些?
  • 所以我有一个主要功能,当有人加载包时我希望它可见。这个特殊的功能被标记为#' @export。然后我有 30 个其他函数被主函数使用,但没有用#' @export 标记。这些将与包一起加载,但我不希望它们可供用户使用。
  • 您是否使用 RStudio 构建包?你检查了Build &gt; Configure Build Tools &gt; Generate Documentation with Roxygen &gt; Configure &gt; Install and Restart 吗? (有时会重置)

标签: r r-package roxygen2


【解决方案1】:

因此,由于某些原因,当我将 NAMESPACE 从 export(myfunction) 修改为 export("myfunction") 时,我得到了预期的结果。

也可以使用#' @export "myfunction"和Roxygen2语法来实现。

【讨论】:

    猜你喜欢
    • 2017-02-16
    • 1970-01-01
    • 1970-01-01
    • 2019-08-20
    • 1970-01-01
    • 1970-01-01
    • 2021-02-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多