knitr::opts_knit$set(root.dir = rprojroot::find_rstudio_root_file()) # Set WD to Root
knitr::opts_chunk$set(eval = FALSE)
here::i_am("dev/build.Rmd")
library(here)

PKG Version

# increments the version field in DESCRIPTION
usethis::use_version("patch")

Release

usethis::use_github_release()

1. PKG File Structures

fs::dir_create("dev") # Public R-Markdown to develop
# fs::dir_create("my_data") # Contain my private data
# fs::dir_create("my_R") # Contain my personal R script file 

2. Git & Build

usethis::use_git()

Git Ignore

# usethis::use_git_ignore("folder_name")
# usethis::use_git_ignore("my_dev/") # Private Dev
usethis::use_git_ignore("*.nb.html") # HTML notebook files
usethis::use_git_ignore("my_data/") # My private data
# usethis::use_git_ignore("testdata/") # ignore private Test Data in `inst/testdata`

Build Ignore

R will not build theses files. If "file A" is build ignored but not git ignored, "file A" will available on github, but not in an installed binary package. Useful for tutorial

# usethis::use_build_ignore("folder_name")
# Ignore Dev/
usethis::use_build_ignore("dev") 
usethis::use_build_ignore("my_data") 

Github Links

Run after add remote repo on Github

usethis::use_github_links()

R CMD Check

This will

  1. create YAML file in .github/workflows/
  2. Adding R-CMD-check badge to 'README.Rmd'

When Push to Github R-CMD-Check will run on Ubuntu

# usethis::use_github_actions()

usethis::use_github_action_check_release()

# usethis::use_github_action_check_standard()

See more at: - How to Github Action - Github Action WF

Test coverage workflow

  1. Call usethis::use_coverage()
usethis::use_coverage()
  1. Set github action
use_github_action("test-coverage")

Ref

This will connect your package to codecov.

Click on codecov badges, it will link to site, then copy token to clip board.

# covr::codecov(token = "")
  1. Package Coverage (Local)

covr

covr::package_coverage()

for interactive use in viewer pane

covr::report()

3. DOCs

DESCRIPTION

rstudioapi::navigateToFile("DESCRIPTION")
# usethis::use_description(
# fields = list(
#   Title = "What The Package Does (one line, title case required)",
#   `Authors@R` = 'person("Kittipos", "Sirivongrungson", 
#                         email = "ki11ip0.s.a.s@gmail.com", 
#                         role = c("aut", "cre"))',
#   Description = "What the package does (one paragraph)",
#   License = "MIT + file LICENSE",
#   Depends = "R (>= 2.10)"
#   )
# )

LICENSE

usethis::use_mit_license()

README

usethis::use_readme_rmd()
usethis::use_lifecycle_badge("experimental")

# Figure in README
fs::dir_create(here("man/figures"))

NEWS

NEWS

usethis::use_news_md()

Vignette

usethis::use_vignette("labChartHRV")

Logo

# usethis::use_logo("man/figures/logo.png")

Template

# usethis::use_rmarkdown_template(
#   template_name = "name",
#   template_dir = "dir-name",
#   template_description = "description",
#   template_create_dir = FALSE
#   )

4. Dependencies

Import

usethis::use_pipe()
# usethis::use_tibble() # If package use `tbl_df` class
usethis::use_package("purrr")
usethis::use_package("dplyr")
usethis::use_package("stringr")
usethis::use_package("readtext")

# Dev Package
# usethis::use_dev_package("pkg", remote = "Lightbridge-KS/pkg")

Suggest

usethis::use_package("glue", type = "Suggests")

Import from

# usethis::use_import_from("rlang", ":=") # Must have if use rlang

Global variables

# Put this in  R/globals.R
# utils::globalVariables(c("var1"))
usethis::use_r("globals.R")

5. Tests

usethis::use_testthat()

Helper Functions for test -> create tests/testthat/helper.R manually

fs::file_create(here("tests/testthat/helper-test.R"))

If you want to use data for testing, put data file(s) in inst/testdata. The path to this data can be obtained by system.file("testdata",...,package="my_package").

For example, If I put cars.csv in inst/testdata, to read into R use this command read.csv(system.file("testdata","cars.csv", package="my_package")).

ref

Path to testdata folder: put this in tests/testthat/helper.R:

path_testdata <- function(..., package = "pkg_name") {

  system.file("testdata", ... ,package = package)

}

6. Data

Exported Data

To store exported data in data/. Each file in this directory should be .rda file containing a single object.

To store code that used for data preparation in data-raw/

# usethis::use_data(export_df1,export_df2) 

usethis::use_data(HRV_vars_desc, overwrite = T) 
usethis::use_data_raw("HRV_vars_desc") # Code to Prepare data
# usethis::use_data_raw("export_df2") # Code to Prepare data
usethis::use_data(HRV_vars_domain)
usethis::use_data_raw("HRV_vars_domain")

How to Document a Data set

Document the name of the data in R/ as roxygen2:

usethis::use_r("data")
#' 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:
#' \describe{
#'   \item{price}{price, in US dollars}
#'   \item{carat}{weight of the diamond, in carats}
#'   ...
#' }
#' @source \url{http://www.diamondse.info/}
"diamonds"

Internal Data

Save all of the objects for internal use in R/sysdata.rda. Usually, they don’t need to be documented.

# usethis::use_data(df1, df2, df3, internal = TRUE)

# Lookup Table for HRV -> use as function instead
# usethis::use_data(regex_hrv, internal = TRUE)
# usethis::use_data_raw("regex_hrv")

Raw Data

If you want to show examples of loading/parsing raw data, put the original files in inst/extdata.

fs::dir_create("inst/extdata")

Function: Path to Raw Data

So that User can easy access path to raw data

usethis::use_r("example") 
usethis::use_test("example")
#' Get path to labChartHRV example
#'
#' labChartHRV comes bundled with a number of sample files in its `inst/extdata`
#' directory. This function make them easy to access
#'
#' @param path Path to example file or folder. If `NULL`, the example files or folders will be listed.
#' @export
#' @examples
#' library(labChartHRV)
#' labChartHRV_example()
#' labChartHRV_example("HRV")
labChartHRV_example <- function(path = NULL) {

  if (is.null(path)) {
    dir(system.file("extdata", package = "labChartHRV"))

  } else {
    system.file("extdata", path, package = "labChartHRV", mustWork = TRUE)
  }

}

labChartHRV_example()
labChartHRV_example("HRV")
labChartHRV_example("HRV/file1.txt")

Write: Raw Data

# raw_data %>% readr::write_csv(here("inst/extdata/file.csv"))


Lightbridge-KS/sipsANS documentation built on June 11, 2022, 8:12 a.m.