生物香火0.1.0.
什么?
描述
:标题,作者,版本,许可等命名空间
:由您的包使用和提供的功能r /
:函数的恶性男子/
:帮助页面鸽子/
:Gignettes.测试/
:测试包的代码为什么?
最小
$树mypackage mypackage└──0目录,1文件$ cat mypackage / description包:mypackage类型:包版本:0.0.1作者:martin摩根维护者:martin morgan 标题:最小值包描述:包装的抽象描述。许可证:艺术-2.0
典型的
$树。└─────────────────────────────────r││──testthat.r└──vignettes└──mypackage.rmd 6目录,7个文件
建造
$ r cmd build mypackage *检查文件'mypackage / description'...正常*准备'mypackage':*检查说明元信息...正常*检查源中的LF线路结束并制作文件和shell脚本*检查空或不需要的目录*创建默认命名空间文件*构建'mypackage_0.0.1.tar.gz'
查看
$ r cmd检查mypackage_0.0.1.tar.gz *使用日志目录'/home/mtmorgan/a/biocintro/vignettes/mypackage.rcheck'*使用R版本3.4.2修补(2017-10-12 R73550)*使用平台:x86_64-pc-linux-gnu (64-bit) * using session charset: UTF-8 * checking for file 'MyPackage/DESCRIPTION' ... OK * checking extension type ... Package * this is package 'MyPackage' version '0.0.1' * checking package namespace information ... OK * checking package dependencies ... OK * checking if this is a source package ... OK * checking if there is a namespace ... OK * checking for executable files ... OK * checking for hidden files and directories ... OK * checking for portable file names ... OK * checking for sufficient/correct file permissions ... OK * checking whether package 'MyPackage' can be installed ... OK * checking installed package size ... OK * checking package directory ... OK * checking DESCRIPTION meta-information ... OK * checking top-level files ... OK * checking for left-over files ... OK * checking index information ... OK * checking package subdirectories ... OK * checking whether the package can be loaded ... OK * checking whether the package can be loaded with stated dependencies ... OK * checking whether the package can be unloaded cleanly ... OK * checking whether the namespace can be loaded with stated dependencies ... OK * checking whether the namespace can be unloaded cleanly ... OK * checking loading without being on the library search path ... OK * checking examples ... NONE * checking PDF version of manual ... OK * DONE Status: OK
安装
$ r cmd安装mypackage_0.0.1.tar.gz *安装到library/home/mtmorgan/r/x86_64-pc-linux-gnu-library/3.4-bioc-3.6'*安装*源*包'mypackage'..。** help No man pages found in package 'MyPackage' *** installing help indices ** building package indices ** testing if installed package can be loaded * DONE (MyPackage)
r / foo.r.
命名空间
要导入函数使用的函数或软件包,并导出用户将要使用的功能。男子
手工页面rshowdoc(“r-exts”)
devtools :: create()
包骨架。更灵活作者@ R.
代替作者:
/维护者:
字段。使用'roxygen'文档功能
#'
是文档线@细节
那@Param.
那@返回
那@例子
记录功能@出口
表示函数应该对用户可见@进口
和@进口于
表示此功能使用的(非基础)函数,例如,。@importomfrom stats rnorm runif
devtools :: document()
更新文档。#'标题,例如,对朋友说'嗨'。#'#'简短此帮助页面的描述。“嗨(”马丁“)`返回一个问候语。#'#'@details对此帮助页面上记录的功能或其他对象#的更广泛描述。使用`如何确定#'问候语的性质。#'#'@param是谁的人/人迎接的人名字。#'#'@param字符(1)是否喊(大写)或耳语#'(小写)问候语。#''@return字符()问候,长度等于`谁。#'#'@examples#'嗨(c(“martin”,“jenny”),“whisper”)#'#'@export嗨< - 函数(谁,何处= c(“asis”,“shout”,“耳语”)){stopfnot(是character(谁),是。特征(如何),丢失(如何)||长度(如何)== 1)变换< - 交换机(匹配匹配(如何),ASIS = identity, shout = toupper, whisper = tolower ) greet <- paste("hi", who) transform(greet) }
使用devtools从中构建/检查/安装R.包文件夹中的会话。
getwd()#e.g.,mypackage / devtools :: build()devtools :: check()devtools :: install()
在开发期间,短路全往返devtools :: load_all()
在Markdown中写Vignettes,例如,vignettes / mypackage.rmd.
。USETHIS :: USE_VIGNETTE()
(也可以看看生物焦)。
- 标题:“mypackage介绍”作者: - 姓名:马丁摩根派聘者:罗斯威尔公园癌症研究所,布法罗,纽约小插图:|%\ vignetteIndexentry {mypackage介绍}%\ vignetteengine {knitr :: Rarmardown}%\ vignetteencoding {UTF-8}它有喊叫或窃窃私语的提示,或者只是在正常的声音中说话。后者通常最适合交朋友。#用来使用此包,将其加载它```{r}库(mypackage)````并迎接一个或多个朋友。```{r}嗨(c(“martin”,“jenny”))```喊你的朋友很难听到或似乎无视你```{r} hi(c(“martin”,“珍妮”),“喊”)“喊道”)```耳语更亲密的情况或避免困扰别人。```{r}嗨(“马丁”,“耳语”)```#会话信息```{r} sessioninfo()```
写单位测试验证您的功能的正确性。USETHIS :: USE_TESTTHAT()
$树。......├──测试│├──testthat││── - test_hi.r│── - testthat.r ...
内容test_hi.r.
:
test_that(“hi()说嗨”,{heipper_true(hi startswith(hi(“x”),“hi”))heepect_true(all(startswith(hi(letters),“hi”)))))})test_that(“嗨()'谁等于输出长度“,{x < - ”x“epection_equal(长度(x),长度(hi(x)))x < - c(”x“,”y“)期望(长度(x),长度(hi(x)))x < - 字符()peepent_equal(length(x),length(hi(x)))})test_that(“hi()obeys'how ='',{Heippe_equal(“嗨x”,hi(“x”,“shout”))期望_equal(“嗨x”,hi(“x”,“耳语”))期望(“嗨xx”,hi(“xx”))peepent_equal(“嗨xx”,hi(“xx”,“asis”))})test_that(“hi()检查输入”,{ippent_error(hi(123),“是.character \\(who \\)是不是真的“)peepent_error(hi(”x“,character()),”缺少\\(何种\\)||长度\\(如何\\)== 1不是真的“)预期_Error(嗨(”x“,”时髦“),”'arg'应该是“Asis”,\“呐喊”,\“耳语”)})
过程
r cmd检查
那r cmd bioccheck.
(后Bioclite(“Bioccheck”)
)手动评论
常见意见
tempfile()
而不是硬编码路径seq_len(n)
而不是1:n ..
sqrt(x)
代替sapply(x,sqrt)
。rtracklayer :: import.bed()
,而不是重新发明。摘要()
而不是矩阵
。避免高'圈复杂性'
NA.
值,正确(比较sapply(Integer(),sqrt)
和Vapply(Integer(),sqrt)
)。从字面上,功能“适合你的头脑”。