Skip to content

Latest commit

 

History

History
59 lines (39 loc) · 1.37 KB

Day2_lab.md

File metadata and controls

59 lines (39 loc) · 1.37 KB

Package Development Lab Day 2

Joyce Robbins

Create a package (only if you missed Day 1)

OR: fork and clone: https://github.com/jtr13/covidtime

  1. Create the package file structure by typing the following in the Console. Choose the path carefully so that you don’t create a package inside another project.
library(devtools)
create_package("~/covidtime")  # you can change the path

Your RStudio session will now switch to the new covidtime package project.

  1. Create a new R script, type in the following function, and save it as day.R in the R folder:
whatdayisit <- function() {
  format(Sys.Date(), "%A, %B %d, %Y")
}

New Stuff

Dependencies

Add a line to whatdayisit() that indicates the number of days to the next month using lubridate::rollforward().

Run usethis::use_package("lubridate").

Checking

Run devtools::check() or click “Check” in the build pane.

Add a license

Run usethis::use_mit_license("Your name")

Functions

Create a days_to(month) function in covidtime that returns the number of days until the month indicated. month should be entered as a three letter abbreviation.

> daysto("Jul")
Time difference of 169 days

Run-time testing

Use if( )... stop() to stop execution if month isn’t a three letter month abbreviation and provide useful information.