简体   繁体   English

使用roxygen2生成命名空间:一个小例子或模板

[英]Use roxygen2 to generate namespace: a small example or template

Using roxygen2 to generate namespace is completely new to me.使用roxygen2生成namespace对我来说是全新的。 Some related questions have been asked and answered multiple times as well as http://r-pkgs.had.co.nz/namespace.html .一些相关问题以及http://r-pkgs.had.co.nz/namespace.html已被多次询问和回答。 I still find it difficult for me.我仍然觉得这对我来说很困难。 I definitely need to read more on this topic.我绝对需要阅读更多关于这个主题的内容。 Meanwhile, I just wonder if someone could offer a simple example of code to quickly get me into it first.同时,我只是想知道是否有人可以提供一个简单的代码示例来让我先快速入门。

I'm not sure the following information will help.我不确定以下信息是否会有所帮助。 I have several functions in the package.我在 package 中有几个功能。 The DESCRIPTION includes something like: DESCRIPTION包括以下内容:

Imports: 
   dplyr, 
   ggplot2,
   survival

Thanks,谢谢,

Try to create a function within the R folder of you package.尝试在 package 的 R 文件夹中创建 function。

Something like就像是

#' Function to plot something
#' 
#' @param my_data a data frame
#' @param x column name for x axis
#' @param y column name for y axis
#' @export
#' @import ggplot2
#' @examples
#' plotSomething(iris, 'Sepal.Length', 'Sepal.Width') 
plotSomething <- function(my_data, x, y) {
  ggplot(my_data, aes_string(x=x, y=y)) + geom_point()
}

The keywords @export and @import will be parsed by roxygen2 and will update the NAMESPACE file after using devtools::document() .关键字@export@import将被roxygen2解析,并在使用devtools::document()后更新NAMESPACE文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM