if (FALSE) {
need("dplyr")
need("dplyr", "tidyr")
# All unnamed arguments will be combined into one list of package names
shared_deps <- c("dplyr", "tidyr")
need(shared_deps, "stringr") # same as need("dplyr", "tidyr", "stringr")
# You can require a minimum version for some or all packages
need("dplyr>=1.0.0", "tidyr")
# Typically you'll want to use need() within a function
read_data <- function(path, clean_names = FALSE) {
# Call need() as early as possible, to avoid wasted work
if (isTRUE(clean_names))
suggests::need("janitor")
output <- utils::read.csv(path)
if (isTRUE(clean_names))
output <- janitor::clean_names(output)
output
}
# You can provide a custom message and/or installation command if needed
need(
"dplyr",
msg = "We need the development version of dplyr, for now!",
install_cmd = quote(remotes::install_github("tidyverse/dplyr"))
)
}
Run the code above in your browser using DataLab