· web viewhow to use github for version control and collaboration and how to write an r package...

Post on 21-Feb-2020

0 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

How to use GitHub for version control and collaboration and how to write an R packageAdam B. Smith | Missouri Botanical Garden | www.EarthSkySea.orgDistributed under the Creative Common License CC BY-SA | 2019-01

Best practices in data management

Please see “Lab Documents” on the Global Change Conservation Lab’s website

Best practices in coding

Please see “Lab Documents” on the Global Change Conservation Lab’s website

Version control using Git and GitHub

GitHub website Creating a repository using GitHub Desktop

o To make a GitHub repository from a folder that already has R scripts:GH Desktop: File Add local repository… Follow directions then select “Create new repository”

o Which license? Usually GPL3.o The README fileo Branchingo Pull requestso Collaborating, conflicts, and merging

Installing an R package from GitHub:

devtools::install_github('userName/repositoryName')

Creating an R package in RStudio

RStudio: File New Project… Folder structure of a package DESCRIPTION file

o Depends / Imports / Suggests Functions

o Documentation Title Description @param: Argument description

\code{words here} words here \emph{words here} words here **words here** words here

@return: What the function produces @seealso: Links to related functions

Linking to another function: \code{\link[packageName]{functionName}}

1

@details: More info @examples: Runnable examples

Can put examples you don’t want tested inside of

\donttest{ <code>}

@export – always include to make the function publicly “visible” in the package!

o The function Arguments and argument defaults The “…” Calling other functions in a function: Always use

<packageName>::<functionName> as in:mgcv::gam(y ~ x1 + x2, data=data)

except for functions in the base package (just use the function name) as in:

print(‘hi world’)o Compiling the package

Generating help: devtools::document() or Build Tab More Document

Compiling: CNTL + SHFT + B or Build Tab More Clean and Rebuild Creating a ZIP or TAR file with the package: Build Tab More Build

Binary Package You then use the ZIP or TAR file to install the package in R

2

top related