New R Package ‘foo’ — Updated

[This article was first published on triKnowBits, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

# RUN THESE LINES IN ONE SESSION …

# Navigate where you want your folder to be located
setwd(“C:/Users/myhandle/Documents/Github”)
# Run create_package in ‘usethis’ package and read below what happens
usethis::create_package(“foo”)
# A bunch of stuff shows up in the console including line below.
# ✔ Opening ‘foo/’ in new RStudio session

# WHEN SWITCHED TO A DIFFERENT SESSION, RUN THESE LINES BELOW

# Add a test environment and add your first test script
usethis::use_testthat()
setwd(“R”) # this is where you need to be
usethis::use_test(“firsttest”) # edit your first test; close
setwd(“..”)
# That will create a file ‘test-firsttest.R’ in foo\tests\testthat
# LICENSE…not necessary, but Check Package will issue warning without it
#  Open DESCRIPTION — just click in RStudio
#  Assuming GPL-3 …
#  Replace
#   License: What license it uses
# with
#   License: GPL-3 | file LICENSE
#
# Put a LICENSE file in the root. In RStudio, File, New File, Text File
#   “GPL3 License file”
# as the sole contents works for me, or the license here:
https://www.gnu.org/licenses/gpl-3.0.txt
# File, Save As, LICENSE
# roxygenise to create help files, run tests, etc.
roxygen2::roxygenise()
# Your package is ready to be checked.
# In RStudio Menu, go to Build, Check (as in “check package integrity”)
# All should check ok, no errors, no problems.
# Write some code.
# Then roxygen2::roxygenise() and Build, Check
# Repeat
# When ready to build the actual package
# In RStudio Menu, go to Build, Install and Restart

That’s it.

Note: Whenever you add new functionality from another package, don’t forget to change the DESCRIPTION file — roxygen can’t do that for you

To leave a comment for the author, please follow the link and comment on their blog: triKnowBits.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)