Apr 24, 2020

New R Package 'foo' -- Updated


RUN THESE LINES IN AN R SESSION ...

# Navigate to where you want your folder to be located
setwd("C:/Users/chief/Documents/Github")
# Run create_package in 'usethis' package and read below what happens
usethis::create_package("foo")
# Messages show up in the console including this line
# ✔ Opening 'foo/' in new RStudio session
WHEN SWITCHED TO THE NEW SESSION, RUN THESE LINES / EXECUTE THESE STEPS ...

# 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.

No comments:

Post a Comment