knitr::opts_chunk$set(echo = TRUE, eval = FALSE)

Introduction

The following code outlines the key steps I use to set up the framework for a package, principally using the usethis package.

Packages

I use these packages for setting things up

library(devtools)
library(usethis)
library(here)

Create repository usig GitHub

I create git repo via the GitHub website,

Assocaite working directy with repo using RStudio

the cloned into it by hand by creating an RStudio Project.

Set up package with usethis

I then use usethis::create_package() within my project directory to build the basic package infrastructure This overights the initial project (after a handy prompt in the console).

usethis::create_package(path = getwd())

Create vignette infrastructure

I create vignette infrastructure and dummy vignette

usethis::use_vignette("temp")

I then write my vignettes using this template and change the file name. I use "a)", "b)", "c)" as a prefix on my vignettes so that show up in order when the website is rendered using packagedown.

Copy in package-making script

I copy this script and related ones for maintaining the package into the vignettes folder.

Create "readme" and "news" files

usethis::use_readme_md()
usethis::use_news_md()

Populating the readme file

I add basic information to the readme fill and add sample code for a call to devtools::install_github() to install the package. The chunk below is an example:

Example materials for readme

The developement version of sparrow telomeres is on GitHub. If you don't already have it, you will need to install the devtools package

install.packages("devtools")

You can then install the sparrowtelomeres from GitHub with:

devtools::install_github("brouwern/sparrowtelomeres")

Create git ignore

Add typical files to gitignore: '.Rproj.user', '.Rhistory', '.Rdata', '.DS_Store'

usethis::git_vaccinate()

I always have trouble with gitingore and haven't taken the time to learn more about it. Am not sure how to use this properly yet.

use_git_ignore(".pdf", directory = ".")
use_git_ignore(".xls", directory = ".")
use_git_ignore(".xlsx", directory = ".")
use_git_ignore(".docx", directory = ".")

Add required packages

these are the packages I typically use. I should vectorize this so it would look nicer : )

usethis::use_package("ggplot2", "Imports")
usethis::use_package("lme4", "Imports")
usethis::use_package("tufte",   "Imports")
usethis::use_package("formatR",   "Imports")
usethis::use_package("readxl",   "Imports")
usethis::use_package("cowplot",   "Imports")
usethis::use_package("ggpubr",   "Imports")
usethis::use_package("dplyr",   "Imports")
usethis::use_package("pander",   "Imports")
usethis::use_package("plotrix",   "Imports")
usethis::use_package("here",   "Imports")
usethis::use_package("pbkrtest",   "Imports")
usethis::use_package("lmerTest",   "Imports")
usethis::use_package("reshape2",   "Imports")
usethis::use_package("arm",   "Imports")
usethis::use_package("blme",   "Imports")



# docxtractr



#usethis::use_package("dplyr",   "Imports")
#usethis::use_package("tidyr",   "Imports")

#usethis::use_package("ggpubr",  "Imports")

# use_package("nlme", "Imports")
# 
# use_package("bbmle", "Imports")
# use_package("RCurl", "Imports")
# use_package("GGally", "Imports")
# use_package("broom", "Imports")

# use_package("arm", "Imports")

# devtools::use_package("data.table", "Imports")
# devtools::use_package("car", "Imports")
# devtools::use_package("lawstat", "Imports")
# devtools::use_package("effsize", "Imports")
# devtools::use_package("here", "Imports")
# devtools::use_package("metafor", "Imports")
# devtools::use_package("Formula", "Imports")
# devtools::use_package("data.tree", "Imports")

Don't save/load user workspace between sessions

usethis::use_blank_slate()

Use roxygen for documentation

Where would we be without roxygen?!?

usethis::use_roxygen_md()

Package-level documents

"Adds a dummy .R file that will prompt roxygen to generate basic package-level documentation. "

usethis::use_package_doc()

Use pkgdown

For making front end website

usethis::use_pkgdown()

Set up data

Create folder for external data.

R packages often have a folder called "/inst" which stands for "installed." This folder is usually for miscellaneous files associated with the package. This includes external data ("/extdata") such as .csv files.

dir.create(here::here("/inst"))
dir.create(here::here("/inst/extdata"))

This could be done with use_directory()

Look at data in my extdata file

External data is stored in "/inst/extdata"

list.files(here::here("/inst/extdata"))

Raw data

I copy raw data files into the "/inst/extdata".

Raw data prep

If there are any data processing steps that I don't want to include in the vignettes I put them into the directory "packagename/data-raw". This structure for this directory and data prep script can be made using use_data_raw()

usethis::use_data_raw()

License

For information on licenses see http://kbroman.org/pkg_primer/pages/licenses.html

Plaintext versions of licenses can be found at https://creativecommons.org/2011/04/15/plaintext-versions-of-creative-commons-licenses-and-cc0/

usethis::use_gpl3_license(name = "Nathan Brouwer")

Spell check

I usually spell check as I go. You can add spell checking as a unit test using use_spell_check()

Other potentially useful usethis functions



brouwern/sparrowtelomeres documentation built on May 23, 2020, 12:34 a.m.