Junzhe Shao 10/21/2021
Credit to John Muschelli
check your name is available on CRAN, Bioconductor or GitHub
library(available)
available("ssmimputedemo")
\~/man/xx.Rd …… R documentation \~/DESCRIPTION ……. sample description file: Package: ssmimputedemo Type: Package Title: SSM Imputation DEMO(Title Case) Version: 0.1.0 Author: Junzhe Shao Maintainer: The package maintainer yourself@somewhere.net Description: More about what it does (maybe more than one line) Use four spaces when indenting paragraphs within the Description. A demo for SSM Imputation License: GPL-3 Encoding: UTF-8 LazyData: true
Build -> install and restart
library(ssmimputedemo)
## Loading required package: tibble
?hello
Build -> Configure Build Tools -> Build Tools Configure Roxygen -> Check everything cran check : –as-cran to be more stable
roxygen file automatically create .Rd file any time we recompile the package
Code ->insert roxygen skeleton
#' @title
#' @description
#' My hello world function
#' @param x The name of person to say hi to
#'
#' @return The output from \code{\link{print}}
#' @export
#'
#' @examples
#' hello("Steve")
#' \dontrun{
#' hello("Steve")}
tab auto completion for @__, will create title and description exactly the same. can link you to outside, examples and function
Build -> clean and rebuild
ℹ Loading ssmimputedemo Warning: The existing ‘hello.Rd’ file was not generated by roxygen2, and will not be overwritten. Warning: The existing ‘NAMESPACE’ file was not generated by roxygen2, and will not be overwritten.
delete these files with default setup Build -> clean and rebuild
export(hello), let the users using hello
check package
creater a new printer funtion, you can add multiple files
library(usethis)
#automaticlly create a readme file
use_readme_rmd()
#push to github, set github remote repository
use_git(message = "")
use_github(protocol = "https")
really nice to add these RoxygenNote: 7.1.2 URL: https://github.com/Junzheshao5959/ssmimputedemo BugReports: https://github.com/Junzheshao5959/ssmimputedemo/issues
using vignette https://r-pkgs.org/vignettes.html
use_vignette("SSM_vignette")
Suggests: knitr, rmarkdown VignetteBuilder: knitr importFrom(tibble,as_data_frame)
automatically add
use_package("tibble")
Depends: tibble
You can use check package to see if there is any function not imported.
Check changes from timeline
use_github_actions()
codecov()
https://app.travis-ci.com/github/Junzheshao5959/ssmimputedemo/builds
Let’s do some test
usethis::use_testthat()
## ✓ Setting active project to '/Users/junzheshao/Documents/ssmimputedemo'
## • Call `use_test()` to initialize a basic test file and open it for editing.
library(testthat)
create a file under \~/test/testthat, like this:
test_that("test test",{
set.seed(123)
res = printer(x = rnorm(5), r = rnorm(5))
expect_that(nrow(res) ,equals(5) )
})
Addins: calculate packge coverage or you can
covr::package_coverage(type = 'all')
## ssmimputedemo Coverage: 100.00%
## R/hello.R: 100.00%
## R/printer.R: 100.00%
use_data_raw()
set.seed(123)
library(dplyr)
x = rnorm(100)
y = rnorm(100)
sample_data = tibble(x = x, y = y)
usethis::use_data(sample_data, compress = "xz")
You will have sampe_data.rda under the \~/data folder
library(ssmimputedemo)
head(sample_data)
## # A tibble: 6 × 2
## x y
## <dbl> <dbl>
## 1 -0.560 -0.710
## 2 -0.230 0.257
## 3 1.56 -0.247
## 4 0.0705 -0.348
## 5 0.129 -0.952
## 6 1.72 -0.0450
?sample_data
you can also create a website by package down.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.