%\VignetteEngine{knitr::knitr} %\VignetteIndexEntry{11 BestPractices—Slides} \documentclass[xcolor=dvipsnames]{beamer} \usepackage{biocutorslides} \hypersetup{colorlinks,linkcolor=,urlcolor=Blue} \AtBeginSection[] {\begin{frame} {Outline} \tableofcontents[currentsection] \end{frame}} \begin{document} < >= library(knitr) opts_chunk$set(tidy=FALSE) @ \title{最佳实践}\author{Martin Morgan (\href{mailto:mtmorgan@fhcrc.org}{mtmorgan@fhcrc.org}) \\ Fred Hutchinson癌症研究中心\\ Seattle, WA} \date{2月7日WA} \maketitle \begin{frame}[fragile]{最佳实践}\begin{enumerate} \item编写有组织的、一致的\R{}代码\item使用版本控制\item文档函数\item编写测试\item编写小片段\item创建一个包(!)\item那么\software{Rstudio}呢?这很简单!示例:使用\Rclass{GRanges}的实用程序,例如\Rfunction{isSimpleVariant}。看到< > =系统。@ \end{frame} \begin{frame}[fragile]{编写有组织的,一致的\R{}代码}\begin{itemize} \item将经常使用的命令组织成不太复杂的函数\item采用一致的\href{//www.andersvercelli.com/developers/how-to/coding-style/}{coding conventions} \begin{itemize} \item函数和变量名\item缩进\item行长度\item \ldots \end{itemize} \item将函数组织成文件,例如:2021欧洲杯体育投注开户一个函数每个文件\begin{逐字}|——GRangesUtilities |——R |——issimplevvariant。R |——stickFigure。R |——vignettes |——UsingGRangesUtilities。Rmd \end{verbatim} \end{itemize} \end{frame} \begin{frame}{使用版本控制}\begin{itemize} \item在您的文档开发过程中轻松地跟踪更改,而无需使用令人困惑的文件命名或其他约定。\end{itemize}软件\begin{itemize} \item \ Software {git}——现代,灵活,易于本地使用(不需要服务器)\item \ Software {subversion} (\ Software {svn})——由\Bioconductor{}使用,需要中央服务器\end{itemize}与他人共享\begin{itemize} \item使用\href{http://github.com}{github},或\ ldots \项目让你的男人建立一个软件\ {git}或{svn} \软件服务器群组的使用\{逐条列记}\{帧}结束\{帧}(脆弱)开始使用版本控制——\软件{git}{}{逐条列记}\ \开始项目变成你开始你的项目的目录\开始{逐字}$ cd GRangesUtilities \{逐字}\项目结束初始化一个{git} \软件存储库和检查状态\{逐字}开始git init git美元地位\{逐字}结束\项目创建/编辑文件,目录\ ldots;$ git添加R/ issimplevvariant。R $ git status \end{逐字}\item提交更改\begin{逐字}$ git Commit \end{逐字}\end{itemize} \end{frame} \begin{frame}{文档函数}\begin{itemize} \item用途:文档如何使用\ emh {function} \item \texttt{man}目录,使用' \texttt{Rd}'文件,组织方式类似\texttt{R}文件,例如\texttt{issimplevvariant。可选:使用\Rpackage{roxygen2}包添加“注释”,例如,到\R{}代码。\end{itemize} \end{frame} \begin{frame}{编写测试}\href{//www.andersvercelli.com/develope2021欧洲杯体育投注开户rs/how-to/unitTesting-guidelines/}{Unit tests} \begin{itemize} \item对每个功能特定部分的简短测试,在\texttt{tests}目录\item \Rpackage{testthat}框架\item \Rpackage{RUnit}框架中实现,用于\Bioconductor{} \end{itemize}测试驱动开发\begin{itemize} \item编写单元测试,描述预期功能\emph{在}实现代码之前。 \end{itemize} \end{frame} \begin{frame}{Write vignettes} Why? \begin{itemize} \item Purpose: document how to use several functions in an integrated way \item `Literate' programming: Text, figures, tables surrounding \R{} script \end{itemize} How? \begin{itemize} \item Write documents in a directory \texttt{vignettes} \item \texttt{Rmd}: `markdown' and \R{} -- easy \item \texttt{Rnw}: `Sweave' combines \LaTeX{} and \R{} to produce PDF documents -- flexible \end{itemize} \end{frame} \begin{frame}{Create a package} \begin{itemize} \item Why? Easy to re-use, share with others (e.g., lab members) \item How? -- \Rcode{RShowDoc("R-exts")} \end{itemize} From what we've already done\ldots \begin{itemize} \item Add a \texttt{DESCRIPTION} file \item Arrange for tests to be run when the package is checked \end{itemize} Additional (optional) steps \begin{itemize} \item \texttt{data} directory of \R{} data objects \item \texttt{inst/script} of \R{} scripts \end{itemize} \end{frame} \begin{frame}[fragile]{Making a package available to your colleagues} \Rpackage{roxygen2}-ize to create NAMESPACE, \texttt{man} pages \begin{verbatim} $ R -e "roxygen2::roxygenize('GRangesUtilities')" \end{verbatim} Build, check, and install the package \begin{verbatim} $ R CMD build GRangesUtilities $ R CMD check GRangesUtilities_0.0.1.tar.gz $ R CMD INSTALL GRangesUtilities_0.0.1.tar.gz \end{verbatim} Final step within \R: \begin{verbatim} install.package("GRangesUtilities_0.0.1.tar.gz", repos=NULL) \end{verbatim} Windows: create a \texttt{.zip} file for easy installation \begin{verbatim} $ R CMD INSTALL --build GRangesUtilities_0.0.1.tar.gz \end{verbatim} \end{frame} \begin{frame}[fagile]{Use it!} < >= library(GRangesUtilities) ?isSimpleVariant vignette("UsingGRangesUtilities") example(isSimpleVariant) @ \end{frame} \end{document}