You can create a package in two ways:
From RStudio, go to the menu bar, go to File, New Project, Choose New Directory, and then select R Package, after giving the project a name click Create Project
Using devtools, you can run the following code in R:
devtools::create("path/to/package/packagename")
generate_cars <- function(n_cars = 100, dep = 0.50, new = 15000) { data.frame(mileage_per_year = rpois(n_cars, lambda = 50000)) %>% dplyr::mutate(price = new - dep * mileage_per_year) }
Recommendations:
Imports:
Suggest:
Imports: ggvis (>= 0.2), dplyr (>= 0.3.0.1)
Important if you want to publish your package on CRAN/share your package:
#' @export foo <- function(x, y, z) { ... }
This is important regardless of whether you want to publish on CRAN or not:
General recommendations:
Use the roxygen2 package
Hadley’s steps:
#' Generates simulated car dataset #' #' This function generates a dataset that simlulates #' random mileage per year using parameters for the number #' of cars, the depreciation rate, and the average price #' of a new car. #' @param n_cars number of cars #' @param dep depreciation rate #' @param new average value of a car when new #' @return a dataset #' @examples #' generate_cars(n_cars = 100, dep = 0.50, new = 15000)
To create your vignette:
This will :
Then you can:
library(hexSticker) imgurl <- here::here("images/vroom.png") # give path of image hexSticker::sticker(imgurl, # image path package = "vroomr", # package name on sticker p_size = 8, # size of package name text p_color = "#BD1816", # color of package name text s_x = 1, # x position for plot/image s_y = 0.75, # y position for plot/image s_width = 0.6, # width of plot/image h_fill = "#ffffff", # hexagon fill color h_color = "#BD1816", # hexagon border color filename = # output location here::here("images/vroomr_hex.png"))