Skip to content
R for the Rest of Us: A Statistics-Free Introduction is out now! Check it out →
R for the Rest of Us Logo

Adding functions to our package

This lesson is locked

Get access to all lessons in this course.

If the video is not playing correctly, you can watch it in a new window

Transcript

Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.

Your Turn

  • Create a new file with use_r() called “db_con”

  • Put this function in the file and save it

  • Use load_all() to load the package function.

  • Run this code to make sure it works

use_r("db_con")

in R/db_con.R:

db_con <- function(dbname = "residents_per_sector") { 
            dbname <- match.arg(dbname)
         # We'll pretend we've connected to a database
         # and just return some hard-coded data instead. 
            data.frame(
            sector = as.factor(1:8),
            residents = c(1000, 2034, 4594, 2304, 8093, 1200, 300, 2398))
}

Have any questions? Put them below and we will help you out!

You need to be signed-in to comment on this post. Login.