Trinostics

WELCOME TO TRINOSTICS

How to start a new package with testing in r

From RStudio

# This post is written this way so you can copy and paste into a

# new file in RStudio and hit Run line-by-line. Edit as necessary.


# Navigate where you want your folder to be located

setwd("C:/Users/chief/Documents/Github")

# Assumes usethis is installed

usethis::create_package("chief")

# R will try to put you into the new project 'chief'.

# If you don't move to the new project, continue with setwd below.

# Add a test environment

setwd("chief") # not necessary if you moved to the project

usethis::use_testthat()


# Add your first test function to at least get something in that folder.

# Go to chief\tests\testthat

# and add this file with name test_chief.R

context("chief")

test_that("I'm testing something", {

  # do something with your code

  expect_equal(1:4, 1:4) # this surely will pass the test

})


# If you want to add a vignette, you can follow along at this Hadley site

#    http://r-pkgs.had.co.nz/vignettes.html 

# which is slightly out of date but should still work despite whatever

# deprecation warnings you may get -- the affordable, IMO, cost of 

# Hadley's rapid evolution approach to code development.

# ... with a straggling "recursive" deprecation as of 7/2/2019:

usethis::use_vignette("my-vignette")


# After writing a function with roxygen comments, roxygenize your package

roxygen2::roxygenise()


# Then click "Check" under RStudio's Build tab

# You may get a warning about "Non-standard license specification".

# To clean that up, see below.


# Next steps: 

# Write more code and re-roxygenize before re-Checking.

# Repeat until all your tests pass and your package checks out clean.

# Once no errors, click "Install and Restart" and your package is done.


You're Done!


# Don't forget!

# The only thing roxygen doesn't handle is, 

# whenever you add new functionality from another package, 

# you have have to change DESCRIPTION.


License

Assuming you just go GPL 

Open DESCRIPTION

Replace "What license it uses" with

GPL-3 | file LICENSE

and put a file named LICENSE in the same directory as DESCRIPTION.

For me, this file content sufficed

"Something about GPL"

but the GNU community would probably prefer you used the one here

 https://www.gnu.org/licenses/gpl-3.0.txt 




image2