vignettes/create_update_package_information.Rmd
create_update_package_information.Rmd
This documents the functions to run to help create and update a R package. Further information can be found at
usethis::use_blank_slate turn off saving and restoring workspace between sessions
usethis::use_blank_slate(scope = "project")
usethis::create_package create the skeleton package directory structure, opening the package in a new R Studio session as a new project
usethis::create_package("C:/Files/packages/store")
usethis::use_description update the title, author and description details in the description file
usethis::use_description(fields = list(Title = "Store commonly used functions and lookups",
`Authors@R` = person("Graham", "French",
role = c("aut", "cre"),
email = "gcfrench@googlemail.com"),
Description = "This package stores the commonly used
functions and lookups, along with function tests and
documentation. These can be then used when creating new
packages by copy and pasting the relevant R scripts and
associated test scripts into the new package, as well as
updating the pkgdown file",
URL = "https://gcfrench.github.io/store"))
usethis::use_cc0_license add one of the license options for the package
usethis::use_cc0_license()
usethis::use_readme_rmd add a readme file, removing the default text from the file. This file is displayed as the front home page in the pkgdown website
usethis::use_readme_rmd()
usethis::use_news_md add a news file, removing the default text from the file. This file will contain the news on each version release
usethis::use_news_md()
## package_name 0.0.0.9000 <font size="4">yyyy-mm-dd</font>
usethis::use_pipe add the %>% pipe operator with the addition of the utils-pipe.R file and magrittr package to the imports field in the description file
usethis::use_pipe()
usethis::use_data_raw add the data-raw directory and empty lookup_raw containing the scripts used to format and add lookup datasets
usethis::use_data_raw("lookup_raw")
usethis::use_testthat add the testthat directory used to contain the test scripts and testthat package to suggests field in the description file
usethis::use_testthat()
devtools::document add the man directory containing the document .Rd files. Documents can also be updated using Ctlr-shift-D or through the Build:Document menu
devtools::document()
usethis::use_pgkdown add the _pkgdown.yml file used to create the menu structure for the package website
usethis::use_pkgdown()
pkgdown.yml template
title: ""
template:
params:
bootswatch: flatly
reference:
- title: ""
desc: ""
#- contents:
# - function_name
navbar:
left:
- icon: fa-home fa-lg
href: index.html
- text: "information"
menu:
# - text: ""
# href: articles/script_name.html
- text: "lookups and functions"
href: reference/index.html
# - text: "analyses"
# menu:
# - text: ""
# href: articles/script_name.html
# - text: "submissions"
# menu:
# - text: ""
# href: articles/script_name.html
- text: "archive"
menu:
# - text: ""
# href: articles/script_name.html
- text: "tasks"
href: articles/tasks.html
- text: "versions"
href: news/index.html
right:
# - icon: "fab fa-twitter fa-lg"
# href: https://twitter.com/gcfrench
# - icon: "fab fa-github fa-lg"
# href: https://github.com/gcfrench/store
usethis::use_lifecycle add the lifecycle badges in the man directory
usethis::use_lifecycle()
usethis::use_lifecycle_badge add lifecycle badge to home page
usethis::use_lifecycle_badge("experimental") # "experimental", "stable". "superseded", "deprecated"
usethis::use_vignette add tasks vignette
usethis::use_vignette("tasks")
This **tasks** section contains a list of tasks and questions, with
their current status
- ✔️ completed
- ❗ awaiting completion
- ✖️no longer needed
- ❓question to be answered
## Tasks and questions
### YYYY-MM-DD
usethis::use_logo add a hex logo to home page
# create hex logo using hexmake https://connect.thinkr.fr/hexmake
usethis::use_logo("image_path")
pkgdown::build_site build documentation
pkgdown::build_site()
usethis::use_git initiates a Git repository, making the initial commits
usethis::use_git()
usethis::use_github creates the repository on Github and pushes the initial commits. This needs a Github Personal Access Token (PAT) which can be created using usethis::create_github_token. Information on how to do this can be found in Happy Git and Github for the useR
usethis::use_github()
# usethis::create_github_token()
usethis::use_github_action configures files to use github to host package website
usethis::use_github_action("pkgdown")
Navigate to the home project directory first
renv::init initiates the renv environment, creating the renv folder and adding the renv.lock file, linking the relevant packages from the renv cache
renv::init()
renv::status check the renv lock file is up-to-date, run renv::snapshot to update the renv lock file if not
renv::deactivate turn off the renv environment, then manually delete the renv folder and .Rprofile file
renv::deactivate()
Navigate to the home project directory first
renv::activate turn on the renv environment
renv::activate()
renv::restore restore the package versions contained within the renv lock file
renv::restore()
fs::dir_create("man/figures")
fs::dir_create("man/examples")
usethis::use_vignette(“vignette_name”): adds the vignette directory, containing a new vignette. This directory contains the script files. Add eval=False to the knitr::opts_chunk to turn off running the code.
usethis::use_vignette("script_name")
pkgdown::build_articles builds the html files in the articles sub-directory of the docs directory. Update the _pkgdown.yml to contain the link to the html file
pkgdown::build_article("script_name")
# pkgdown::build_articles()
pkgdown::build_articles_index()
usethis::use_r add new r script in the R directory containing functions. Run and edit Roxygen comments using Code:Insert Roxygen skeleton, or Ctlr-Alt-Shift-R. update documentation by runing devtools::document, Ctlr-shift-D or through the Build:Document menu
usethis::use_r("function_script_name")
usethis::use_package add packages to the imports section of the description file
usethis::use_package("package_name")
devtools::document update documentation, can also use Ctlr-shift-D or through the Build:Document menu
devtools::document()
pkgdown::build_reference builds the html files in the reference sub-directory of the docs directory. Update the _pkgdown.yml to contain the link to the html file
pkgdown::build_reference
pkgdown::build_reference_index()
usethis::use_test add unit tests for function
usethis::use_test("test_script_name")
devtools::test run all tests, can also use Ctrl-Shift_T or Build-Test Package
devtools::test()
usethis::use_data_raw add a new data_raw script
usethis::use_data_raw("data_raw_script_name")
usethis::use_data add the .rda data file in the data directory, after running the data raw script so that the data frame is stored in the global environment
usethis::use_data(data_frame_name)
usethis::use_r document the data frame in a R script. Running devtools::document afterwards
usethis::use_r("lookup")
Data frame documentation template
#' Data frame name
#'
#' Data frame description
#'
#' @format A tibble with xx rows and x variables
#' \describe{
#' \item{field_name}{field description}
#' \item{field_name}{field description}
#' }
"data_frame_name"
pkgdown::build_reference builds the html files in the reference sub-directory of the docs directory. Update the _pkgdown.yml to contain the link to the html file
pkgdown::build_reference
pkgdown::build_reference_index()
usethis::use_version update the package version
usethis::use_version()
usethis::edit_file edit the news file with the new package version
usethis::edit_file("News.md")
pkgdown::build_news builds the index.html file in the news sub-directory of the docs directory
pkgdown::build_news()
usethis::edit_file edit the README.Rmd file
usethis::edit_file("README.Rmd")
pkgdown::build_home builds the index.html file in the docs directory
pkgdown::build_home()
Build documentation and test functions, then run Install and Restart to build and install package
pkgdown::build_site run pkgdown::clean_site first to delete files in docs sub-directory
pkgdown::clean_site()
pkgdown::build_site()
pkgdown::deploy_to_branch pushes docs folder to GitHub branch gh-pages.
Need to change repository settings GitHub Pages Source to Branch gh-pages/root. Site published to https://github_name.github.io/package_name
pkgdown::deploy_to_branch()
usethis::edit_file Add URL to description and README files