Skip to contents

Check 🛠 Docs 📚 Code Coverage 📔

GitHub forksGitHub Repo stars

GitHub commit activityGitHub contributorsGitHub last commitGitHub pull requestsGitHub repo sizeGitHub language countProject Status: Active – The project has reached a stable, usable state and is being actively developed. Current Version Open Issues

dunlin provides a variety of data tools to reformat and manipulate a subset of the tables in a data set stored.

Installation

It is recommended that you create and use a GitHub PAT to install the latest version of this package. Once you have the PAT, run the following:

Sys.setenv(GITHUB_PAT = "your_access_token_here")
if (!require("remotes")) install.packages("remotes")
remotes::install_github("insightsengineering/dunlin@*release")

Usage

library(dm)
library(dunlin)

db <- dm_nycflights13()

new_carrier <- c(NA, "", as.character(db$airlines$carrier[-c(1, 2)]))
new_name <- c(NA, "", as.character(db$airlines$name[-c(1, 2)]))

db <- db %>%
  dm_zoom_to("airlines") %>%
  mutate(
    carrier = new_carrier,
    name = new_name
  ) %>%
  dm_update_zoomed()

db$airlines

which returns airlines as

# A tibble: 15 × 2
   carrier name
   <chr>   <chr>
 1  NA      NA
 2 ""      ""
 3 "AS"    "Alaska Airlines Inc."
 4 "B6"    "JetBlue Airways"
 5 "DL"    "Delta Air Lines Inc."
 6 "EV"    "ExpressJet Airlines Inc."
 7 "F9"    "Frontier Airlines Inc."
 8 "FL"    "AirTran Airways Corporation"
 9 "HA"    "Hawaiian Airlines Inc."
10 "MQ"    "Envoy Air"
11 "UA"    "United Air Lines Inc."
12 "US"    "US Airways Inc."
13 "VX"    "Virgin America"
14 "WN"    "Southwest Airlines Co."
15 "YV"    "Mesa Airlines Inc."
new_format <- list(
  airlines = list(
    carrier = rule("No Coding available" = c("", NA, "<Missing>")),
    name = rule("<Missing>" = c("", NA, "<Missing>"))
  )
)

db <- dunlin::reformat(db, new_format, na_last = TRUE)

db$airlines

which reformulates airlines as

# A tibble: 15 × 2
   carrier             name
   <fct>               <fct>
 1 No Coding available <Missing>
 2 No Coding available <Missing>
 3 AS                  Alaska Airlines Inc.
 4 B6                  JetBlue Airways
 5 DL                  Delta Air Lines Inc.
 6 EV                  ExpressJet Airlines Inc.
 7 F9                  Frontier Airlines Inc.
 8 FL                  AirTran Airways Corporation
 9 HA                  Hawaiian Airlines Inc.
10 MQ                  Envoy Air
11 UA                  United Air Lines Inc.
12 US                  US Airways Inc.
13 VX                  Virgin America
14 WN                  Southwest Airlines Co.
15 YV                  Mesa Airlines Inc.