-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.R
More file actions
26 lines (25 loc) · 892 Bytes
/
setup.R
File metadata and controls
26 lines (25 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
packages = c("dplyr", "data.table","tidytable", "nycflights13", "sf")
installed = installed.packages()
for (package in packages){
if (!package %in% rownames(installed)){
install.packages(package)
}
suppressPackageStartupMessages({
library(package, character.only = TRUE)
})
}
#' Read in the `flights` data as a user-specified type
#' of data frame
#'
#' @param type chr, the type of table to return
#' @return a data frame of the specified type
read_flights = function(type = c("data.frame",
"tibble",
"data.table",
"tidytable")[1]){
switch(tolower(type[1]),
"data.frame" = as.data.frame(flights),
"tibble" = dplyr::as_tibble(flights),
"data.table" = data.table::as.data.table(flights),
"tidytable" = tidytable::as_tidytable(flights))
}