knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(devtools) library(testthat)
At the beginning of a project, run these commands once. No harm will come if you run them again, but you don't need to unless you want to change something.
library(devtools) library(usethis) # Create a new package path <- file.path(tempdir(), "mypkg") create_package(path) # Modify the description use_mit_license("My Name") # Add packages to use in package use_package("MASS", "Suggests") # Set up other files use_readme_rmd() #to update readme build_readme() # use test-that use_testthat() # Use git use_git()
Follow the instructions here: https://usethis.r-lib.org/articles/articles/git-credentials.html#practical-instructions-1. Have a look at the topic on 'scope' in particular.
# check your settings gh_token_help() git_sitrep() # find and remove legacy credentials in `.Renviron` (`GITHUB_PAT` or `GITHUB_TOKEN`) usethis::edit_r_environ() # create a personal access token on github usethis::create_github_token() # enter PAT to local git credentials store gitcreds::gitcreds_set()
Once the package has been set up, the workflow is:
# create or edit a script use_r("myscript1") # adding data for tests use_data_raw(name = "mydataset") #create script for making dataset #example content of data file: x <- 1 y <- 2 use_data(x, y) # load load_all() # write test use_test("myscript1") #creates or opens a test file #example content of test file: test_that("multiplication works", { expect_equal(2 * 2, 4) }) # test test()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.