zzz3-creating_this_package.Rmd
The following code outlines the key steps I use to set up the framework for a package, principally using the usethis package.
I create the git repo via the GitHub website: https://github.com/brouwern/compbio4all.git
Clone into the repo by hand by creating an RStudio Project: New project / New repro / etc
I then use usethis::create_package() within my project directory to build the basic package infrastructure This overwrites the initial project (after a handy prompt in the console).
usethis::create_package(path = getwd())
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.
I copy this script and related ones for maintaining the package into the vignettes folder.
usethis::use_readme_md()
usethis::use_news_md()
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:
The development version of compbio4all 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 compbio4all from GitHub with:
devtools::install_github("brouwern/compbio4all")
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. I am not sure how to use this properly yet.
usethis::use_git_ignore(".pdf", directory = ".")
usethis::use_git_ignore(".xls", directory = ".")
usethis::use_git_ignore(".xlsx", directory = ".")
usethis::use_git_ignore(".docx", directory = ".")
these are the packages I typically use. I should vectorize this so it would look nicer : )
usethis::use_package("ape", "Suggests")
usethis::use_package("phangorn", "Suggests")
usethis::use_package("ggplot2", "Imports")
usethis::use_package("ggpubr", "Imports")
usethis::use_package("rentrez", "Imports")
usethis::use_package("seqinr", "Imports")
#usethis::use_package("UniprotR", "Imports") # not used?
usethis::use_package("Biostrings", "Imports") # oh boy
usethis::use_package("MASS", "Imports")
usethis::use_package("scatterplot3d", "Suggests")
usethis::use_package("GGally", "Suggests")
usethis::use_package("cowplot", "Imports")
usethis::use_package("pander", "Imports")
usethis::use_package("bio3d", "Suggests")
usethis::use_package("here", "Imports")
usethis::use_package("survival", "Suggests")
usethis::use_package("reshape2", "Imports")
usethis::use_package("rpart", "Suggests")
# #usethis::use_package("blme", "Imports")
# docxtractr
usethis::use_package("dplyr", "Imports")
usethis::use_package("tidyr", "Imports")
usethis::use_package("stringr", "Imports")
usethis::use_package("evd", "Suggests")
usethis::use_package("HistData", "Suggests")
usethis::use_package("flextable", "Suggests")
usethis::use_package("webshot", "Suggests")
usethis::use_package("cluster", "Suggests")
usethis::use_package("iNEXT", "Suggests")
usethis::use_package("gplots", "Suggests")
# 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")
usethis::use_blank_slate()
Where would we be without roxygen for writing documentation files?!?
usethis::use_roxygen_md()
“Adds a dummy .R file that will prompt roxygen to generate basic package-level documentation.”
usethis::use_package_doc()
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()
External data is stored in “/inst/extdata”
list.files(here::here("/inst/extdata"))
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()
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()
An error can occur if you have a separate license file. eg
File LICENSE is not mentioned in the DESCRIPTION file.
This can be fixed by changing the description from “License: GPL-3” to “License: GPL-3 + file LICENSE”
All data sets must be documented.
# usethis::use_r(name = "fledgedata")
# usethis::use_r(name = "telosfull")
# usethis::use_r(name = "telosfull_focalcols_rnd")
A minimal R dataset .R file looks like this #’ Full dataset dfor Meillere et al. 2015 “telosful”
A standard R dataset .R file looks like this (https://r-pkgs.org/data.html)
#’ Prices of 50,000 round cut diamonds. #’ #’ A dataset containing the prices and other attributes of almost 54,000 #’ diamonds. #’ #’ @format A data frame with 53940 rows and 10 variables: #’ #’ @source “diamonds”