knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE, error = FALSE, results = "asis")
devtools
is a collection of R package developmental toolscreate("project")
creates a project folder for your R packageusethis
creates things for package managementuse_r("file_name")
creates an .R fileroxygen
generates documentationsMore on how to use these packages below... ...
setwd()
in RStudiodevtools::create("<project_name>")
to create a new R project. It will create
the following files inside the project folder:devtools::use_rstudio("<path/to/package>")
.
.Rproj file contains project option informationperson("first_name", "last_name", email = ..., role = c("aut", "cre"))
devtools::use_package("package_name")
to add package dependency to Import: devtools::use_package("package_name", "Suggests")
to add package to Suggests:requireNamespace("package_name", quietly=TRUE)
devtools::use_build_ignore("note")
to modify the .Rbuildignore fileuse_this::use_r("file_name")
to creat a blank .R file in the R folder#------
to break up your code into easily readable chunks#' @title <fxn title>
#' @description <fxn description>
#' @param <name> <description>
#' @return <fxn outupt>
#' @example(s) <example>
(Note: example will need to pass check if it's added to documentation)#' @export
devtools::document()
creates the nicely formatted function documentations,
which are in the Rd files, and they could be converted to HTML or PDF#'@template file_name
), or documentation referencing (#'@inheritParams function_name
)
for consistent function documentationmagrittr
pipe, use usethis::use_pipe()
usethis::use_build_ignore("<file/directory_name>")
devtools::build()
devtools::check()
usethis::use_github_action_check_standard()
for standard checkusethis::use_github_action_check_release()
for quick check.github
folder, a workflows
folder with a
R-CMD-check.yaml
file inside, and a R-CMD-check
badge will be added to the
README.md
Reference: stackoverflow post
cd ~/.config/rstudio
mkdir template
cd template
touch default.R
open default.R
and add to the default.R fileReference: technical guidelines from Mirai Solutions
usethis::use_build_ignore("man-roxygen")
Reference: first edition of R Packages, second edition is work in progress.
devtools
and usethis
? Hmmmdevtools::build()
. Files added to ".Rbuildignore" are not included in the bundle.
Package bundle is generated for code distribution!?install.packages()
download and install
binary packages built by CRAN.devtools::load_all()
and "Build & Reload"?devtools::load_all()
sources all files in R/library()
and require()
? When a package is
not found, library()
throws an error but require()
prints a message and returns
FALSE
.library()
or require()
.DESCRIPTION
lists the packages your package needs. Specify required packages
in DESCRIPTION$Imports
and they will be installed when your package is installed.
List suggested packages under DESCRIPTION$Suggests
, those are the packages can be
used but not required (Not sure if I understand the difference since I would have suggested_package::fxn
even for functions from the suggested packages in my codes,
right?! Okay, I think it means if you have an alternative execution to suggested_package::fxn
,
you can let your package users know that they can use the suggested_package::fxn
with your fxns).
For examples: # Here you are telling your package users that they need to install the suggested_pkg. # Why not put the package under Imports?? If the suggested package is only required # by one less-frequently-used function among many of your other functions, maybe it's # a good idea to let the users install the suggested package when they need it. # When developing package locally, you don't really need to use Suggests. fxn <- function(x, y) { if (!requireNamespace("suggested_pkg", quietly = TRUE)) { stop("Suggested_pkg needed for this function. Please install it.", call. = FALSE) } } # Here you have an alternative execution, but user could also choose to use the # suggested package fxn <- function(x, y) { if (!requireNamespace("suggested_pkg", quietly = TRUE)) { suggested_pkg::fxn() } else { fxn() } }
Imports: pakcage_x (>= version_of_the_pacakge_you_are_using_for_development)
It's important to specify the version of required packages when you release your package
since users might not have the required version installed.
9.
10. R environment is changed sometimes with function calls, for examples, library()
, options()
, and setwd()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.